简体   繁体   中英

Suppress one x-axis, keep the other with ggtree and geom_facet

I'm trying to remove the x-axis from one plot (the tree on the left should have no x-axis labels, ticks, line, etc.), while keeping the x-axis on the plot on the right (0-60, ticks, label: "Number of G's"). I've unsuccessfully searched through nearly all ggtree blogs, ggtree github, ggplot2 help, ggtree help, etc.

The picture shows what my plot looks like without any tip labels or legend: 我的情节没有提示标签或图例

Someone else is looking for an answer to the same question here: 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

I figured it out.

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM