ggplot2/phyloseq: can you extract the coordinates of a richness plot?

Hi there, I'm new to the forum so please excuse me if this topic has been addressed.

I am using the package phyloseq to analyze microbiome community data. If I understand correctly, phyloseq uses ggplot2 to graph results.
From phyloseq, you can graph species richness (a count of the number of species) and a series of other species diversity indices by sample.
I was wondering if there was a way to extract the data from the graph so you can see or output the x y coordinates. The reason for doing this is that you may want to use the x y data in a table rather than a graph, etc.
Here is some code to see how this works:

site_raw = merge_samples(fungi, "Site")
sample_data(site_raw)$Site = sample_names(site_raw)
site_plot <- plot_richness(site_raw, x="Site", measures=c("Observed", "Chao1", "Shannon"))
site_plot2 <- plot_richness(site_raw, x="Site")

Site_plot and site_plot2 are objects that create nice scatterplots of the data. Depending on the species diversity index there may also be standard deviation error bars as well.

Thank you in advance,

Hi everyone, I think I might have figured it out.
if you use the following code, it seems to output the data for each pane (ie. diversity index) of the scatterplot.

site_plot2_data <- ggbuild(site_plot2)
site_plot2_data then outputs the entire data array.

Hi bugguy!

If you are using Phyloseq to calculate the richness and just want the data (not the plots), you should use estimate_richness function within Phyloseq.
The output is a data frame that you can use to plot using ggplot2, make a table, etc.


1 Like

Thank you juanu I will give this a try!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.