researchIMP researchbioinformatics

跟着NatureCommunications学作图:R语言ggt

2022-09-19  本文已影响0人  小明的数据分析笔记本

论文

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")
image.png

示例数据和代码可以给推文点赞 点击在看 最后留言获取

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

上一篇下一篇

猜你喜欢

热点阅读