Is there a way to increase the height of the strip.text bar in a facet?

后端 未结 2 1821
自闭症患者
自闭症患者 2020-12-31 07:24

I would like the grey bar at the top to be wider, as in, have the edges of it a little further from the top and bottom of the letters (the strip.text - A, B, C etc). I would

相关标签:
2条回答
  • 2020-12-31 07:35

    With ggplot2 2.2.0, you can apply Ricardo's trick without modifying the dataframe, by using labeller:

    P <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
      xlim(0, 2) + stat_binhex(na.rm = TRUE)+
      facet_wrap(~ color, labeller = labeller(color=setNames(paste0("\n", levels(diamonds$color), "\n"), levels(diamonds$color))))
    
    P +  theme(strip.text = element_text(size=9, lineheight=0.5))
    
    0 讨论(0)
  • 2020-12-31 07:55

    First, modify the levels so that they include a linebreak:

    levels(diamonds$color) <- paste0(" \n", levels(diamonds$color) , "\n ")
    

    Then adjust as necessary. eg:

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

    lineheight=0.5

    P +  theme(strip.text = element_text(size=9, lineheight=3.0))
    

    lineheight=3.0

    0 讨论(0)
提交回复
热议问题