4. 优势物种展示

简介

优势物种展示。

数据样式:常见丰度表,列为样本,行为物种,交叉区域为各物种在各样本中的丰度。

一般堆叠柱状图

一般选取top10—top15丰度的细菌门类群用于展示其丰度组成,其他的类群合并为“Others”展示;横坐标代表不同测序样本(或分组),纵坐标代表了微生物类群的相对丰度,不同的微生物类群用不同颜色展示。

library(tidyverse)
# input OTUs 
otu_table  <-  read.delim("16S-amplicon-analysis/otutab.txt", header=T, sep="\t", row.names=1, stringsAsFactors = FALSE)

metadata <- read.delim("16S-amplicon-analysis/metadata.txt", header=T, sep="\t", stringsAsFactors = FALSE)

taxonomy <- read.delim("16S-amplicon-analysis/clean_taxonomy.txt", header=T, sep="\t", stringsAsFactors = FALSE)


otu_table$OTUs <- rownames(otu_table)
genus <- subset(taxonomy, select = c(OTUs, genus))
  
temp <- merge(otu_table, genus, by = "OTUs", )
temp <- subset(temp, select = -OTUs)

temp %>% 
  group_by(genus) %>% 
  summarise_all(sum) -> genus_table

genus_table <- as.data.frame(genus_table)
genus_table <- na.omit(genus_table)
rownames(genus_table) <- genus_table$genus
genus_table <- subset(genus_table, 
                      select = -c(genus))
# rowsums and sorted
genus_table$rowsum <- rowSums(genus_table)
genus_table <- genus_table[order(genus_table$rowsum, 
                                 decreasing = TRUE), ]
# top 10
genus_top10 <- genus_table[1:10, ]
genus_top10['Others', ] <- colSums(genus_table) - colSums(genus_top10)


# # 若Others已经在top10内 
# genus_top10["rest", ] <- colSums(genus_table) - colSums(genus_top10)
# genus_top10["The_others", ] <- genus_top10["Others", ] + genus_top10["rest", ]

# check 
check_top <- function(top_table, otu_table){
  judge <- colSums(genus_top10) == colSums(otu_table)
  if (sum(judge) == length(otu_table)){
    print("Everything looks good")}
  else{print("something wrong.")}
}

check_top(genus_top10, genus_table)

## [1] "Everything looks good"

# make factor levels 
genus_top10$Taxo <- fct_inorder(rownames(genus_top10))


temp <- pivot_longer(data = genus_top10, 
                     cols = -c(Taxo, rowsum),
                     names_to = "Sample", 
                     values_to = "value")

plot_data <- merge(temp, metadata, by = "Sample")

ggplot(data = plot_data , aes(x = Sample, y = value, 
                              fill = Taxo)) + 
  geom_col(position = 'fill', width = 0.6) +
  facet_wrap(~ Group, scales = 'free_x', ncol = 3) +
  scale_fill_brewer(palette = "Set3") +
  labs(x = '', y = 'Relative Abundance(%)') +
  theme(panel.grid.minor.y = element_line(colour = "black"),
        panel.background = element_rect(color = 'black', 
                                        fill = 'transparent'))
plot.png

堆叠图连线

  1. 根据各分组数据获得起点终点坐标,利用geom_segment()做连线。

  2. ggalluvial

img

物种度聚类热图

根据所有样本在属水平的物种注释及丰度信息,选取丰度排名前35的属,从物种和样本两个层面进行聚类并绘制成热图,便于发现哪些物种在哪些样本中聚集较多或含量较低。

library(pheatmap)
# top 30
genus_top30 <- genus_table[1:30, ]
# genus_top30['Others', ] <- colSums(genus_table) - colSums(genus_top30)

plot_mat <- subset(genus_top30, select = -rowsum)
annot_col <- data.frame(row.names = colnames(plot_mat), 
                         group = metadata$Group)

pheatmap(mat = plot_mat, annotation_col = annot_col)
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • QIIME 2不仅可用于处理标记基因分析,而且 在广泛的用户和社区人员参与开发下,已经产生了很多 可用插件 ,在未...
    吴十三和小可爱的札记阅读 4,529评论 0 10
  • 1. 随机森林模型 随机森林是一种基于决策树(Decisiontree)的高效的机器学习算法,可以用于对样本进行分...
    JarySun阅读 5,870评论 0 20
  • 熊金波实验室出品 整理归纳:Larry 本次学习使用的服务器IP地址和其用户名账户密码如下: 地址:gs0.gen...
    Larrylu007阅读 27,883评论 10 106
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,590评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,620评论 0 11