## Load Package and Example Data ```{r message=FALSE} library(phyloseq); packageVersion("phyloseq") packageVersion("ggplot2") data(enterotype) ``` There is a random aspect to some of the network layout methods. For complete reproducibility of the images produced later in this tutorial, it is possible to set the random number generator seed explicitly: ```{r} set.seed(711L) ``` Because we want to use the enterotype designations as a plot feature in these plots, we need to remove the 9 samples for which no enterotype designation was assigned (this will save us the hassle of some pesky warning messages, but everything still works; the offending samples are anyway omitted). ```{r} enterotype = subset_samples(enterotype, !is.na(Enterotype)) ``` ## The plot_net function The newer `plot_net` function does not require a separate `make_network` function call, or a separate `igraph` object. For examples running the older `plot_network` function, which may provide some added flexibility with igraph objects, see the `plot_network` section later. Try `plot_net` with the default settings. ```{r} plot_net(enterotype, maxdist = 0.4, point_label = "Sample_ID") ``` The previous graphic displayed some interesting structure, with one or two major subgraphs comprising a majority of samples. Furthermore, there seemed to be a correlation in the sample naming scheme and position within the network. Instead of trying to read all of the sample names to understand the pattern, let's map some of the sample variables onto this graphic as color and shape: ```{r} plot_net(enterotype, maxdist = 0.3, color = "SeqTech", shape="Enterotype") ``` In the previous examples, the choice of maximum-distance and distance method were informed, but arbitrary. Try what happens when `maxdist` value is decreased (hint: this will usually decrease the number of edges in the network). ## The plot_network function Create an igraph-based network based on the default distance method, "Jaccard", and a maximum distance between connected nodes of `0.3`. ```{r} ig <- make_network(enterotype, max.dist=0.3) ``` Now plot this network representation with the default settings. ```{r} plot_network(ig, enterotype) ``` The previous graphic displayed some interesting structure, with a major subgraph comprising a majority of samples. Furthermore, there seemed to be a correlation in the sample naming scheme and position within the network. Instead of trying to read all of the sample names to understand the pattern, let's map some of the sample variables onto this graphic as color and shape: ```{r} plot_network(ig, enterotype, color="SeqTech", shape="Enterotype", line_weight=0.4, label=NULL) ``` In the previous examples, the choice of maximum-distance and distance method were informed, but arbitrary. Let's see what happens when the maximum distance is lowered, decreasing the number of edges in the network ```{r} ig <- make_network(enterotype, max.dist=0.2) plot_network(ig, enterotype, color="SeqTech", shape="Enterotype", line_weight=0.4, label=NULL) ``` Let's repeat the previous exercise, but replace the Jaccard (default) distance method with Bray-Curtis ```{r} ig <- make_network(enterotype, dist.fun="bray", max.dist=0.3) plot_network(ig, enterotype, color="SeqTech", shape="Enterotype", line_weight=0.4, label=NULL) ```