抑制一个 x 轴,使用 ggtree 和 geom_facet 保留另一个

问题描述

我试图从一个图中删除 x 轴(左侧的树应该没有 x 轴标签、刻度、线等),同时将 x 轴保留在右侧的图中(0-60,刻度,标签:“G 的数量”)。我几乎搜索了所有 ggtree 博客、ggtree github、ggplot2 帮助、ggtree 帮助等都没有成功。

图片显示了我的情节在没有任何提示标签或图例的情况下的样子:

my plot without tip labels or legend

其他人正在此处寻找同一问题的答案:https://groups.google.com/g/bioc-ggtree/c/CPb1C955PHo

p <- ggtree(phylo) +  geom_tiplab(offset=1,hjust=.8,size=2.5) + 
     geom_facet(panel="GS",data=res3,geom = ggstance::geom_barh,mapping = aes(x= Freq,group= as.factor(res3$CG),fill= GS),color='grey90',lwd=.3,stat="identity") +
    theme_tree2(legend.position=c(.85,.45)) +
    scale_x_continuous(breaks = c(0,5,10,15,20,30,40,50,60)) + 
    theme(strip.background = element_blank(),strip.text = element_blank()) +
    scale_fill_manual(name = "GS",values=c("#0072B2","#D55E00","#E69F00","#F0E442","#999999","#009E73"))

p

解决方法

我想通了。

phylop <- ggtree(phylo) +  geom_tiplab(offset=0.1,hjust=0,size=2.5) + xlim_tree(5.3)
bars <-  ggplot(res3,aes(y= Freq,x= as.factor(CG))) + geom_col(aes(fill=GS)) + 
    # geom_text(aes(label=CG,y= Freq)) +
    coord_flip() + 
    scale_y_continuous(breaks = c(0,1,2,3,4,5,10,15,20,30,40,50,60)) + 
    theme_tree2() + theme(legend.position=c(.70,.65)) +
    scale_fill_manual(name = "GS",values=c("#0072B2","#D55E00","#E69F00","#F0E442","#999999","#009E73"))

cowplot::plot_grid(phylop,bars,ncol=2) 

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...