Learn R Programming

poppr (version 2.9.6)

imsn: Create minimum spanning networks interactively

Description

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.

Usage

imsn()

Arguments

Value

NULL, invisibly

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.

Author

Zhian N. Kamvar

Details

Creating and plotting MSNs requires three steps:

  1. Create a distance matrix from your data

  2. Create a minimum spanning network with your data and the matrix

  3. 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.

See Also

plot_poppr_msn diss.dist bruvo.dist bruvo.msn poppr.msn nei.dist popsub missingno

Examples

Run this code
if (FALSE) {

# Set up some data
library("poppr")
library("magrittr")
data(monpop)
splitStrata(monpop) <- ~Tree/Year/Symptom
summary(monpop)
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
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() 
}
}

Run the code above in your browser using DataLab