编辑条带大小ggplot2

Al1*_*l14 13 r ggplot2

我试图应用这个解决方案(如何在ggplot中更改小平面上的条带大小1)更改ggplot中小平面上的条带大小,我增加了高度大小

library(ggplot2)
library(gtable)

d <- ggplot(mtcars, aes(x=gear)) + 
            geom_bar(aes(y=gear), stat="identity", position="dodge") +
            facet_wrap(~cyl)

g <- ggplotGrob(d)
g$heights[[3]] = unit(5,"in")

grid.newpage()
grid.draw(g)
Run Code Online (Sandbox Code Playgroud)

这是我得到的,它只增加了条带顶部的空白(白色): 在此输入图像描述

为什么它的工作方式不同?

wic*_*ici 25

一个简单的解决方案是strip.text适当地指定元素的边距:

ggplot(mtcars, aes(x=gear)) + 
  geom_bar(aes(y=gear), stat="identity", position="dodge") +
  facet_wrap(~cyl) + 
  theme(strip.text.x = element_text(margin = margin(2,0,2,0, "cm")))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述