我希望顶部的灰色条更宽,因为它的边缘距离字母的顶部和底部稍远一些(strip.text - A,B,C等).我本以为行高会起到填充的作用,但事实并非如此.
ggplot(diamonds, aes(carat, price, fill = ..density..)) +
xlim(0, 2) + stat_binhex(na.rm = TRUE)+
facet_wrap(~ color) +
theme(strip.text = element_text(lineheight=20))
Run Code Online (Sandbox Code Playgroud) 我试图应用这个解决方案(如何在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)
为什么它的工作方式不同?
###Load libraries
library(ggplot2)
library(gtable)
###Build plot
d <- ggplot(mtcars, aes(x=gear)) +
geom_bar(aes(y=gear), stat="identity", position="dodge") +
facet_wrap(~cyl)
###Change height of strip text
g <- ggplotGrob(d)
g$heights[[3]] = unit(2,"in")
grid.newpage()
grid.draw(g)
Run Code Online (Sandbox Code Playgroud)
ggplot2_2.0.0)ggplot2_1.0.1)中土世界到底发生了什么?