将“facet_grid”条带与多面画布隔开?

bal*_*lin 4 r ggplot2

考虑以下示例?ggplot2::facet_grid

p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p + facet_grid(vars(drv), vars(cyl))
Run Code Online (Sandbox Code Playgroud)

结果如下图 在此处输入图片说明

我想要实现的是 facet-labeling strips 和实际图之间的较小偏移/空白。结果看起来(没有gimp参与): 在此处输入图片说明

是否可以使用ggplot2或其任何衍生软件包?

感谢您的任何见解。

Tun*_*ung 5

有一个选项strip.switch.pad.grid,但只有在激活switch参数时才有效

library(ggplot2)
theme_set(theme_bw(base_size = 14))

p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p + facet_grid(vars(drv), vars(cyl), 
               switch = 'y') +
  theme(strip.placement = 'outside') +
  theme(strip.switch.pad.grid = unit('0.25', "cm"))
Run Code Online (Sandbox Code Playgroud)

reprex 包(v0.2.1)于 2019-05-15 创建


bal*_*lin 5

跟进上面@Tung 的分析器(以及一些无视文档的实验),我让它开始工作:

p <- ggplot(mpg, aes(displ, cty)) + geom_point() 
p +
  facet_grid(vars(drv), vars(cyl)) +
  theme(strip.switch.pad.grid = unit(0.2, "cm"), strip.placement = "outside")
Run Code Online (Sandbox Code Playgroud)

还有……多多!:

在此处输入图片说明