There are many useful examples of phyloseq network graphics in the
phyloseq online tutorials.
A custom plotting function for displaying networks
using advanced ggplot2 formatting.
Note that this function is a performance and interface revision to
plot_network, which requires an igraph
object as its first argument.
This new function is more in-line with other
plot_* functions in the phyloseq-package, in that its
first/main argument is a phyloseq-class instance.
Edges in the network are created if the distance between
nodes is below a (potentially arbitrary) threshold,
and special care should be given to considering the choice of this threshold.
However, network line thickness and opacity is scaled according to the
similarity of vertices (either samples or taxa),
helping to temper, somewhat, the effect of the threshold.
Also note that the choice of network layout algorithm can have a large effect
on the impression and interpretability of the network graphic,
and you may want to familiarize yourself with some of these options
(see the laymeth argument).
(Required).
The phyloseq-class object that you want to represent as a network.
distance
(Optional). Default is "bray".
Can be either a distance method supported by distance,
or an already-computed dist-class with labels that match
the indices implied by both the physeq and type arguments
(that is, either sample or taxa names).
If you used distance to pre-calculate your distance,
and the same type argument as provided here, then they will match.
type
(Optional). Default "samples".
Whether the network represented in the primary argument, g,
is samples or taxa/OTUs.
Supported arguments are "samples", "taxa",
where "taxa" indicates using the taxa indices,
whether they actually represent species or some other taxonomic rank.
maxdist
(Optional). Default 0.7.
The maximum distance value between two vertices
to connect with an edge in the graphic.
laymeth
(Optional). Default "fruchterman.reingold".
A character string that indicates the method that will determine
the placement of vertices, typically based on conectedness of vertices
and the number of vertices.
This is an interesting topic, and there are lots of options.
See igraph-package for related topics in general,
and see layout.auto for descriptions of various
alternative layout method options supported here.
The character string argument should match exactly the
layout function name with the "layout." omitted.
Try laymeth="list" to see a list of options.
color
(Optional). Default NULL.
The name of the sample variable in physeq to use for color mapping
of points (graph vertices).
shape
(Optional). Default NULL.
The name of the sample variable in physeq to use for shape mapping.
of points (graph vertices).
rescale
(Optional). Logical. Default FALSE.
Whether to rescale the distance values to be [0, 1], in which the
min value is close to zero and the max value is 1.
point_size
(Optional). Default 5.
The size of the vertex points.
point_alpha
(Optional). Default 1.
A value between 0 and 1 for the alpha transparency of the vertex points.
point_label
(Optional). Default NULL.
The variable name in physeq covariate data to map to vertex labels.
hjust
(Optional). Default 1.35.
The amount of horizontal justification to use for each label.
title
(Optional). Default NULL. Character string.
The main title for the graphic.
Value
A ggplot2 network plot.
Will render to default graphic device automatically as print side effect.
Can also be saved, further manipulated, or rendered to
a vector or raster file using ggsave.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(phyloseq)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/phyloseq/plot_net.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plot_net
> ### Title: Microbiome Network Plot using ggplot2
> ### Aliases: plot_net
>
> ### ** Examples
>
> data(enterotype)
> plot_net(enterotype, color="SeqTech", maxdist = 0.3)
> plot_net(enterotype, color="SeqTech", maxdist = 0.3, laymeth = "auto")
> plot_net(enterotype, color="SeqTech", maxdist = 0.3, laymeth = "svd")
Warning message:
In laymeth(g, ...) :
SVD layout was removed, we use Fruchterman-Reingold instead.
> plot_net(enterotype, color="SeqTech", maxdist = 0.3, laymeth = "circle")
> plot_net(enterotype, color="SeqTech", shape="Enterotype", maxdist = 0.3, laymeth = "circle")
>
>
>
>
>
> dev.off()
null device
1
>