我如何更改ggplot中facet的大小? [英] How can I change the size of the strip on facets in a ggplot?

查看:622
本文介绍了我如何更改ggplot中facet的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以控制ggplot中小平面上的条的大小?我尝试过使用 strip.background = element_rect(size = n),但据我所知它实际上没有做任何事情。这甚至有可能吗?

Is there any way to control the size of the strips on facets in a ggplot? I tried using strip.background=element_rect(size=n) but as far as I can tell it didn't actually do anything. Is this even possible?

推荐答案

手动将图转换为gtable可以调整条高度,

converting the plot to a gtable manually lets you tweak the strip height,

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(1,"in")

grid.newpage()
grid.draw(g)

这篇关于我如何更改ggplot中facet的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆