今天学习绘制下面这个paper里面的一个图。
从图中,可以看出,图片分成2个部分,左边是进化树,右边是类似气泡图。
下面我们用一组简单的文件进行测试:
进化树文件:
(((A8:0.9735669859,((A5:0.7219205995,A9:0.5385038075):0.6462689626,A1:0.3329299772):0.03139768029):0.06015197909,A10:0.4923124262):0.4108513703,(((A6:0.8690173309,A4:0.5830903472):0.309844861,(A3:0.5314095169,A7:0.8771070722):0.7551963951):0.5753640204,A2:0.7064118343):0.2585936433);
这个是一个简单的对每一个节点的分类文件:
library(ggtree)
library(treeio)
library(readxl)
library(tidyverse)
tree<-read.tree("tree.txt")
dat01<-read.table("group.txt",header=T)
tree<-full_join(tree,dat01,by="label")
p1<-ggtree(tree)+
geom_tiplab(align = TRUE,fontface=3)+
geom_tippoint(aes(color=groupinfo),
show.legend = F,
size=5)+
scale_color_manual(values = c('group1'='#df237b','group2'='#11926a'))+
xlim(0,3)
p1
然后,随机生成了一个基本的表达值文件,只做测试,不具备任何生物学意义。
dat02<-read.table("exp.txt",header=T)
dat02$tiplabel<-factor(dat02$tiplabel,levels = p1$data %>% na.omit() %>% arrange(y) %>% pull(label)) #主要调整控制气泡图中sample的顺序,和进化树保持一致
p2 <- ggplot(data=dat02,aes(x=FC,y=tiplabel))+
geom_point(aes(size=Mean,fill=groupinfo),shape=21)+
geom_vline(xintercept = 0,lty="dashed",color="grey")+
facet_wrap(~species,nrow = 1,scales = 'free')+
scale_fill_manual(values = c('group1'='#df237b','group2'='#11926a'))+
guides(size=guide_legend(order = 1), fill=guide_legend(order = 2))+
theme_minimal()+
theme(legend.position = 'bottom',
legend.direction = 'vertical',
legend.justification = c(0,0),
axis.line.x = element_line(),
axis.ticks.x = element_line(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
panel.grid = element_blank(),
strip.background = element_rect(fill = "grey"))
p2
library(patchwork)
p1+p2+plot_layout(widths = c(1,4))