Learn R Programming

phyloseq (version 1.16.2)

plot_network: Microbiome Network Plot using ggplot2

Description

There are many useful examples of phyloseq network graphics in the http://joey711.github.io/phyloseq/plot_network-examples{phyloseq online tutorials}. A custom plotting function for displaying networks using advanced ggplot2 formatting. The network itself should be represented using the igraph package. For the phyloseq-package it is suggested that the network object (argument g) be created using the make_network function, and based upon sample-wise or taxa-wise microbiome ecological distances calculated from a phylogenetic sequencing experiment (phyloseq-class). In this case, 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.

Usage

plot_network(g, physeq=NULL, type="samples", 
	color=NULL, shape=NULL, point_size=4, alpha=1,
	label="value", hjust = 1.35, 
	line_weight=0.5, line_color=color, line_alpha=0.4,
	layout.method=layout.fruchterman.reingold, title=NULL)

Arguments

g
(Required). An igraph-class object created either by the convenience wrapper make_network, or directly by the tools in the igraph-package.
physeq
(Optional). Default NULL. A phyloseq-class object on which g is based.
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.
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).
point_size
(Optional). Default 4. The size of the vertex points.
alpha
(Optional). Default 1. A value between 0 and 1 for the alpha transparency of the vertex points.
label
(Optional). Default "value". The name of the sample variable in physeq to use for labelling the vertex points.
hjust
(Optional). Default 1.35. The amount of horizontal justification to use for each label.
line_weight
(Optional). Default 0.3. The line thickness to use to label graph edges.
line_color
(Optional). Default color. The name of the sample variable in physeq to use for color mapping of lines (graph edges).
line_alpha
(Optional). Default 0.4. The transparency level for graph-edge lines.
layout.method
(Optional). Default layout.fruchterman.reingold. A function (closure) that determines the placement of the vertices for drawing a graph. Should be able to take an igraph-class as sole argument, and return a two-column coordinate matrix with nrow equal to the number of vertices. For possible options already included in igraph-package, see the others also described in the help file:
title
(Optional). Default NULL. Character string. The main title for the graphic.

layout.fruchterman.reingold

Value

  • A ggplot2 plot representing the network, with optional mapping of variable(s) to point color or shape.

References

This code was adapted from a repo original hosted on GitHub by Scott Chamberlain: https://github.com/SChamberlain/gggraph

The code most directly used/modified was first posted here: http://www.r-bloggers.com/basic-ggplot2-network-graphs/

See Also

make_network

Examples

Run this code
data(enterotype)
ig <- make_network(enterotype, max.dist=0.3)
plot_network(ig, enterotype, color="SeqTech", shape="Enterotype", line_weight=0.3, label=NULL)
# Change distance parameter
ig <- make_network(enterotype, max.dist=0.2)
plot_network(ig, enterotype, color="SeqTech", shape="Enterotype", line_weight=0.3, label=NULL)

Run the code above in your browser using DataLab