I intend to plot an alpha diversity plot of my samples, which consist of three groups. Alpha diversity is calculated by R package Di.net. It involve using phyloseq as a dependency.
The group of each sample is specified in a sam_data, column "type" in phyloseq object "df_family" "dv" is list composed of diversity estimates and standard errors.
Here is the code I used:
dv$shannon %>% plot(df_family, color = "type", group = df_family@sam_data$type) +
xlab("sample type") +
ylab("Shannon diversity estimate (family level)") +
coord_cartesian(ylim = c(0,5))`
Here is what I get:
The samples were shown independently, instead of clustered as a group
Here is what I intend to get:
Once you already have your phyloseq object df_family
, you can use the function estimate_richness
from phyloseq. You can then join the sample meta data to this data frame of alpha diversities. Finally, you can use ggplot2
directly to customize your plot accordingly, eg to put different sample groups (here SampleType
) at your x axis:
library(tidyverse)
library(phyloseq)
# get example phy object
otufile <- system.file("extdata", "GP_otu_table_rand_short.txt.gz", package = "phyloseq")
mapfile <- system.file("extdata", "master_map.txt", package = "phyloseq")
df_family <- import_qiime(otufile, mapfile, trefile, showProgress = FALSE)
alphadiv <-
df_family %>%
estimate_richness() %>%
as_tibble(rownames = "sample_id") %>%
left_join(df_family@sam_data %>% as_tibble(rownames = "sample_id"))
alphadiv
alphadiv %>%
ggplot(aes(x = SampleType, y = Shannon)) +
geom_boxplot()
You can also add additional sample properties in aes eg aes(x = SampleType, y = Shannon, color = my_group)
if my_group
is a sample property column with cells containing f, li, or si.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.