在ggplot2中将一个面板空白 [英] make one panel blank in ggplot2
本文介绍了在ggplot2中将一个面板空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
p <- ggplot(mtcars, aes(mpg, wt))
p + geom_point()+facet_grid(cyl ~ vs)+theme_bw()
我想使面板(右下角的1 vs 8)为空白,其中未显示任何数据点,但与此同时,我想保持这种排列方式.
I would like to make the panel (1 vs 8 in the lower right hand corner) blank where no data points are shown, but at the same time, I would like to keep this arrangement.
所以facet_wrap(cyl ~ vs)
无法解决我的问题.
so facet_wrap(cyl ~ vs)
could not solve my problem.
也许更普遍的问题是,是否可以在ggplot2中安排每个面板?
maybe more general question is that is it possible to arrange each panel in ggplot2?
推荐答案
您更改表文件.
## get the table grobs
g1 <- ggplot_gtable(ggplot_build(p))
library(gtable)
library(grid)
## here the main modification
## change one panel by a new rectangle.
pp <- gtable_add_grob(g1,rectGrob(gp=gpar(col=NA)),t=8,l=6,b=8,r=6)
grid.draw(pp)
这篇关于在ggplot2中将一个面板空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文