有没有办法增加一个方面的strip.text栏的高度?

nzc*_*ops 14 r ggplot2

我希望顶部的灰色条更宽,因为它的边缘距离字母的顶部和底部稍远一些(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)

Ric*_*rta 24

首先,修改级别,使其包含换行符:

levels(diamonds$color) <- paste0(" \n", levels(diamonds$color) , "\n ")
Run Code Online (Sandbox Code Playgroud)

然后根据需要调整.例如:

P <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
      xlim(0, 2) + stat_binhex(na.rm = TRUE)+
      facet_wrap(~ color)

P +  theme(strip.text = element_text(size=9, lineheight=0.5))
Run Code Online (Sandbox Code Playgroud)

线高= 0.5

P +  theme(strip.text = element_text(size=9, lineheight=3.0))
Run Code Online (Sandbox Code Playgroud)

线高= 3.0