【发布时间】:2019-06-04 15:53:05
【问题描述】:
考虑下面的分面图,它以 2x2 的排列方式绘制了 3 个分面。空白面在右下角。
library(ggplot2)
ggplot(mtcars) +
aes(x = wt, y = mpg) +
geom_point() +
facet_wrap(~factor(cyl), ncol = 2)
我想生成一个在顶行具有空白面的图,例如如下:
有什么办法可以做到这一点,而不用弄乱 grobs 或 gtable?
【问题讨论】:
-
您可以通过为
cyl添加一个“空白”因子水平来做到这一点。来自?facet_wrap:# To change the order in which the panels appear, change the levels # of the underlying factor. mpg$class2 <- reorder(mpg$class, mpg$displ) ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(~class2)