减少 ggplot2 和 grid.arrange 中的所有绘图边距

Meh*_*i.K 3 r margins ggplot2

我正在尝试使用grid.arrange()和 来编译四个图表,以减少每个图的边距,以便它们美观且紧凑。我想使用theme(plot.margin=unit(c(x, x, x , x), "cm"))(欢迎其他解决方案)。

不久前有人问过类似的问题: here

但是,现在需要没有默认值的plot.margin参数。units我找不到任何关于 R 在这个论证中期望什么的解释。有人能举个例子吗?

如需可重现的示例,请使用旧问题中提供的示例。谢谢!

Jul*_*ora 5

我们的unit(c(t, r, b, l), "cm")边距大小分别位于顶部、右侧、底部和左侧。实际上有一个默认值:

theme_get()$plot.margin
# [1] 5.5pt 5.5pt 5.5pt 5.5pt
Run Code Online (Sandbox Code Playgroud)

一个例子:

qplot(mpg, wt, data = mtcars) + 
  theme(plot.margin = unit(c(5, 15, 25, 35), "pt"),
        plot.background = element_rect(fill = "grey90"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 致OP:记住顺序的一个有用的助记符是***tr**ou**bl**e*。 (8认同)