This function will launch an interactive interface that allows you to create, plot, manipulate, and save minimum spanning networks. It runs using the shiny R package.
Details
Creating and plotting MSNs requires three steps:
Create a distance matrix from your data
Create a minimum spanning network with your data and the matrix
Visualize the minimum spanning network
The function plot_poppr_msn
is currently the most flexible way
of visualizing your minimum spanning network, but with 20 parameters, it can
become pretty intimidating trying to find the right display for your MSN.
With this function, all three steps are combined into one interactive interface that will allow you to intuitively modify your minimum spanning network and even save the results to a pdf or png file.
Interface
Buttons
In the left hand panel, there are three buttons to execute the functions. These allow you to run the data set after you manipulate all of the parameters.
GO! - This button will start the application with the specified parameters
reData - Use this button when you have changed any parameters under the section Data Parameters. This involves recalculating the distance matrix and msn.
reGraph - Use this button when you have changed any parameters under the section Graphical Parameters. This involves superficial changes to the display of the minimum spanning network.
Tabs
The right hand panel contains different tabs related to your data set of choice.
Plot - The minimum spanning network itself
Data - A display of your data set
Command - The commands used to create the plot. You can copy and paste this to an R file for reproducibility.
Save Plot - This provides a tool for you to save the plot to a PDF or PNG image.
Session Information - displays the result of
sessionInfo
for reproducibility.
Examples
# \dontrun{
# Set up some data
library("poppr")
library("magrittr")
data(monpop)
splitStrata(monpop) <- ~Tree/Year/Symptom
summary(monpop)
#>
#> // Number of individuals: 694
#> // Group sizes: 23 41 132 73 5 13 1 64 85 130 30 97
#> // Number of alleles per locus: 3 6 3 11 9 5 8 7 5 9 8 11 10
#> // Number of alleles per group: 48 53 58 48 37 40 13 44 60 64 60 63
#> // Percentage of missing data: 0.51 %
#> // Observed heterozygosity: 0
monpop_ssr <- c(CHMFc4 = 7, CHMFc5 = 2, CHMFc12 = 4,
SEA = 4, SED = 4, SEE = 2, SEG = 6,
SEI = 3, SEL = 4, SEN = 2, SEP = 4,
SEQ = 2, SER = 4)
t26 <- monpop %>% setPop(~Tree) %>% popsub("26") %>% setPop(~Year/Symptom)
t26
#>
#> This is a genclone object
#> -------------------------
#> Genotype information:
#>
#> 155 multilocus genotypes
#> 390 haploid individuals
#> 13 codominant loci
#>
#> Population information:
#>
#> 3 strata - Tree, Year, Symptom
#> 6 populations defined - 9_BB, 9_FR, 10_BB, 10_FR, 11_BB, 11_FR
if (interactive()) {
imsn() # select Bruvo's distance and enter "monpop_ssr" into the Repeat Length field.
# It is also possible to run this from github if you are connected to the internet.
# This allows you to access any bug fixes that may have been updated before a formal
# release on CRAN
shiny::runGitHub("grunwaldlab/poppr", subdir = "inst/shiny/msn_explorer")
# You can also use your own distance matrices, but there's a small catch.
# in order to do so, you must write a function that will subset the matrix
# to whatever populations are in your data. Here's an example with the above
mondist <- bruvo.dist(monpop, replen = monpop_ssr)
myDist <- function(x, d = mondist){
dm <- as.matrix(d) # Convert the dist object to a square matrix
xi <- indNames(x) # Grab the sample names that exist
return(as.dist(dm[xi, xi])) # return only the elements that have the names
# in the data set
}
# After executing imsn, choose:
# Distance: custom
# myDist
imsn()
}
# }