Skip to content
joey711 edited this page Sep 11, 2012 · 2 revisions

Graphic Summary of Richness Estimates

Here is the default graphic produced by the plot_richness function on the GlobalPatterns example dataset, specifying SampleType as the variable on which to map the horizontal axis.

data(GlobalPatterns)
plot_richness(GlobalPatterns, "SampleType")

plot_richness

Now suppose we wanted to use an external variable in the plot that isn't in the GlobalPatterns datasets, say, whether or not the samples are human-associated. First, define this new variable, human, as a factor (other vectors could also work).

# prune OTUs that are not present in at least one sample
GP <- prune_species(speciesSums(GlobalPatterns) > 0, GlobalPatterns)
# Define a human-associated versus non-human categorical variable:
human <- getVariable(GP, "SampleType") %in% c("Feces", "Mock", "Skin", "Tongue")
# Add new human variable to sample data:
sampleData(GP)$human <- factor(human)

Now tell plot_richness to map the new human variable on the horizontal axis, and shade the points in different color groups, according to which SampleType they belong.

plot_richness(GP, human, "SampleType")

plot_richness

Clone this wiki locally