编辑条带大小ggplot2

编辑条带大小ggplot2

本文介绍了编辑条带大小ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图应用此解决方案(


I have tried to apply this solution (How can I change the size of the strip on facets in a ggplot?1) to change the size of the strip on facets in a ggplot, I have increase the height size

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)

This is what I get, it does only increase the space (white) on the top of the strip:

Why does it work differently?

解决方案

A simple solution is to specify the margins of your strip.text elements appropriately:

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")))

这篇关于编辑条带大小ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:24