我正在处理一些我希望显示为nxn网格图的数据.编辑:更清楚的是,我的数据中有21个类别.我希望按类别划分,并将这21个图形放在一个5 x 5平方网格中(其中孤儿本身位于第五行).因此facet_wrap而不是facet_grid.
我已经编写了以下代码(使用旧的虹膜数据集作为我可重现的示例):
library(ggplot2)
library(grid)
cust_theme <- theme_bw() + theme(legend.position="none",
axis.title = element_blank(), axis.ticks = element_blank(),
axis.text = element_blank(), strip.text = element_blank(),
strip.background = element_blank(), panel.margin = unit(0, "lines"),
panel.border = element_rect(size = 0.25, color = "black"),
panel.grid = element_blank())
iris.plot <- ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() + cust_theme + facet_wrap( ~ Species, ncol = 2) +
labs(title = "Irises by species")
Run Code Online (Sandbox Code Playgroud)
这给了我几乎我想要的东西,但并不完全:

我在最上面一排的地块和底行之间仍然留有一小块空间.我想完全摆脱它,但panel.margin显然没有这样做.有没有办法做到这一点?