前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ggplot2优雅绘制蛋白结构域与基因结构图

ggplot2优雅绘制蛋白结构域与基因结构图

作者头像
R语言数据分析指南
发布2022-09-21 14:35:35
1.3K0
发布2022-09-21 14:35:35
举报

❝小编很久之前写过一系列基因家族数据可视化的文档,最近对基因家族数据可视化又有了新的认识下面来绘制这一类文章里面的一张常用图,下面来看具体操作 ❞

绘制进化树

代码语言:javascript
复制
tree <- read.newick("tree.nwk",node.label = "support") %>%
  ggtree(branch.length = "none")+
  theme_void()+
  theme(legend.title=element_blank(),
        legend.position = c(0.1,1.2), legend.justification = c(0,1.2),
        legend.text=element_text(color="black",size=8))

绘制蛋白保守结构域

代码语言:javascript
复制
pfam <- read_tsv("pfam.xls",col_names = F) %>% 
  select(1,4,5,6,12) %>% 
  filter(X12 < 0.001) %>%
  mutate_at(vars("X5"),~str_split(.,"\\.",simplify=TRUE)[,1]) %>% 
  separate(`X5`,into=c("A","B"),sep="-") %>% 
  mutate(A=as.numeric(A)) %>% 
  select(-X12,-B) %>% 
  set_colnames(c("gene","start","end","hmm_acc")) %>% 
  ggplot(aes(xmin = start,xmax = end,y=gene,fill = hmm_acc)) +
  geom_gene_arrow(arrowhead_height = unit(0, "mm"),
                  arrowhead_width = unit(0,"mm"))+
  labs(y=NULL)+
  theme( 
    axis.text.y=element_blank(),
    axis.text.x=element_text(color="black"),
    legend.title = element_blank(),
    legend.spacing.x=unit(0.1,'cm'),
    legend.key.width=unit(0.4,'cm'),
    legend.position = "top",
    legend.text=element_text(color="black",size=8),
    legend.key.height=unit(0.4,'cm'),
    plot.margin=unit(c(0,0,0,0),units="cm"))+
  guides(fill = guide_legend(direction = "horizontal"))+
  guides(fill=guide_legend(nrow=1, byrow=TRUE))

绘制基因结构图

代码语言:javascript
复制
gene <- gggenomes("A.gff") + 
  geom_gene(position="pile",size=3)+
  theme(plot.margin=unit(c(1.1,0,0,0),units="cm"))

拼图

代码语言:javascript
复制
g <- gene %>% pick_by_tree(tree) %>% ggplotify::as.grob() %>% ggdraw()
pp <- tree +pfam+plot_layout(widths = c(.6,1))
(pp %>% ggdraw()|g) +theme(plot.margin=unit(c(0,0,0,0),units="cm"))
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-05-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 R语言数据分析指南 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 绘制进化树
  • 绘制蛋白保守结构域
  • 绘制基因结构图
  • 拼图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档