zl程序教程

您现在的位置是:首页 >  其他

当前栏目

跟着NatureCommunications学作图:R语言ggtree根据分组给进化树上色

2023-02-19 12:27:46 时间

论文

MiDAS 4: A global catalogue of full-length 16S rRNA gene sequences and taxonomy for studies of bacterial communities in wastewater treatment plants

https://www.nature.com/articles/s41467-022-29438-7

数据链接

https://figshare.com/articles/dataset/Dueholm2021a_data_zip/16566408/1

代码链接

https://github.com/msdueholm/MiDAS4

今天的推文我们重复一下论文中的Figure2

image.png

我试了下论文中提供的数据,这个数据量有点大,运行要好长时间,这里的示例数据我们不用论文中的数据了,用自己随便构造的

最基本的进化树可视化

library(ggtree)
library(treeio)


tree <- read.tree("data/20220829/fig2.nwk")
ggtree(tree)+
  geom_tiplab()

image.png

准备表示分组的数据,这里需要用到一个列表格式的数据

groupInfo<-list(group1=c("A","B","C","D","E"),
                group2=c("F","G","H","I","J","K","L","M"))

然后使用groupOTU()函数将分组信息和进化树组合到一起

tree01<-groupOTU(tree,groupInfo)

对结果进行展示

ggtree(tree01,aes(color=group))+
  geom_tiplab(show.legend=F,offset = 1)+
  geom_tippoint(aes(shape=group),
                show.legend = F,
                size=5)

image.png

这里 color=group的group是默认生成的,不用改

更改配色

ggtree(tree01,aes(color=group),size=2)+
  geom_tiplab(show.legend=F,offset = 1)+
  geom_tippoint(aes(shape=group),
                show.legend = F,
                size=5)+
  scale_color_manual(values = c("#fb8d63","#69c0a2"))

image.png

封面图

ggtree(tree01,
       aes(color=group),
       size=2,
       layout = "circular",
       branch.length = "none")+
  geom_tiplab(show.legend=F,offset = 1)+
  geom_tippoint(aes(shape=group),
                show.legend = F,
                size=5)+
  scale_color_manual(values = c("#fb8d63","#69c0a2")) -> p1

p1
ggtree(tree01,aes(color=group),size=2)+
  geom_tiplab(show.legend=F,offset = 1)+
  geom_tippoint(aes(shape=group),
                show.legend = F,
                size=5)+
  scale_color_manual(values = c("#fb8d63","#69c0a2")) -> p2
p2
library(patchwork)

p1+theme(legend.position = "none")+
  p2+theme(legend.position = "none")