RR plot扩增子分析

ggplot2绘制Alpha多样性指数图

2021-01-31  本文已影响0人  R语言数据分析指南

经过前面几节的原始数据处理过程,得到了可以用于分析的数据,现在让我们开始微生物组数据分析可视化的第一步,绘制Alpha多样性指数图,喜欢的小伙伴欢迎关注个人公众号R语言数据分析指南,在此先行拜谢了! 数据见:原文链接

phyloseq整合数据

rm(list=ls())
library(pacman)
pacman::p_load(tidyverse,phyloseq,MicrobiotaProcess,ape,
               patchwork,ggpubr,ggsci)
otu_mat <- read.delim2("otu_table.tsv",header=T,
                       sep="\t",check.names = F,row.names = 1) %>%
  as.matrix()

tax_mat <- read.delim("taxa.xls",header=T,row.names = 1,
                      sep="\t",check.names = F) %>% as.matrix()
samples_df <- read.delim("group.xls",header = T,row.names = 1,
                         sep="\t",check.names = F)
tree <- read.tree("rooted_tree.tre")

OTU = otu_table(otu_mat,taxa_are_rows =T)
TAX = tax_table(tax_mat)
samples = sample_data(samples_df)

ps <- phyloseq(OTU,TAX,samples,tree)
ps

MicrobiotaProcess计算Alpha多样性指数

alphaobj <- get_alphaindex(ps)


head(as.data.frame(alphaobj))

write.table(alphaobj,file="alpha.xls",sep="\t",col.names = NA)

p_alpha <- ggbox(alphaobj, geom="violin",factorNames="group")+
  theme(strip.background = element_rect(colour=NA, fill="grey"))
p_alpha

可以看到MicrobiotaProcess包很轻松就绘制好了Alpha多样性的指数的图,虽然很方便但是如果需要高度自定义还是得通过ggplot2来绘制,下面通过ggplot2来一步步绘制Alpha多样性指数图

自定义主题

theme_niwot <- function(){
    theme_bw()+
    theme(strip.text.x = element_text(colour ="black",size=12),
          axis.text.x = element_text(family = "Times",size=10),
          axis.text.y = element_text(family = "Times",size=10),
          legend.position = "non")}

Shannon

Shannon <- alphaobj %>% as.data.frame() %>% 
  select(Shannon,group) %>%
  mutate(V4="Shannon") %>%
  ggplot(aes(group,Shannon))+
  geom_violin(aes(fill=group),trim=F)+
  geom_boxplot(width=0.03,fill="white")+
  xlab(NULL)+ylab(NULL)+
  scale_fill_nejm()+
  facet_grid(.~V4,scales = "free",space="free_x")+
  stat_compare_means(method = "anova",label.y =6.5,label.x = 2)+
  theme_niwot()

Chao1

Chao1 <- alphaobj %>% as.data.frame() %>% 
  select(Chao1,group) %>%
  mutate(V4="Chao1") %>%
  ggplot(aes(group,Chao1))+
  geom_violin(aes(fill=group),trim=F)+
  geom_boxplot(width=0.03,fill="white")+
  xlab(NULL)+ylab(NULL)+
  scale_fill_nejm()+
  facet_grid(.~V4,scales = "free",space="free_x")+
  stat_compare_means(method = "anova",label.y =1000,label.x = 2)+
  theme_niwot()

ACE

ACE <- alphaobj %>% as.data.frame() %>% 
  select(ACE,group) %>%
  mutate(V4="ACE") %>%
  ggplot(aes(group,ACE))+
  geom_violin(aes(fill=group),trim=F)+
  geom_boxplot(width=0.03,fill="white")+
  xlab(NULL)+ylab(NULL)+
  scale_fill_nejm()+
  facet_grid(.~V4,scales = "free",space="free_x")+
  stat_compare_means(method = "anova",label.y = 1000,label.x = 2)+
  theme_niwot()

Simpson

Simpson <- alphaobj %>% as.data.frame() %>% 
  select(Simpson,group) %>%
  mutate(V4="Simpson") %>%
  ggplot(aes(group,Simpson))+
  geom_violin(aes(fill=group),trim=F)+
  geom_boxplot(width=0.03,fill="white")+
  xlab(NULL)+ylab(NULL)+
  facet_grid(.~V4,scales = "free",space="free_x")+
  scale_fill_nejm()+
  stat_compare_means(method = "anova",label.y =1.005,label.x = 2)+
  theme_niwot()

为了添加分面标签,通过mutate添加了V4列,ggpubr包对整体数据进行Anova分析并添加标签

patchwork拼图

Shannon+ACE+Simpson+Chao1+plot_layout(ncol =2)

原文链接:https://mp.weixin.qq.com/s/Cb5NqNWCqXvGsrm5BdTyDA

上一篇下一篇

猜你喜欢

热点阅读