Remove strip background keep panel border

前端 未结 3 1117
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 04:31

I have the following type of plot and want to keep each strip text above the individual facet box as a \"title\" of sorts yet not have the default grey background and black

相关标签:
3条回答
  • 2020-12-13 05:17

    If you set element_blank() for strip.background and keep element_rect(colour="black", fill = NA) for panel.border then top edge of panel.border will be black. As pointed out by @adrien, for panel.background fill should be set to NA to avoid covering of points (already set as default for theme_bw()).

    ggplot(mtcars, aes(mpg, hp)) + geom_point() +
      facet_wrap(~carb, ncol = 3) + theme_bw() +
      theme(panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            strip.background = element_blank(),
            panel.border = element_rect(colour = "black", fill = NA))
    

    enter image description here

    0 讨论(0)
  • 2020-12-13 05:19

    Setting panel.border might cover your graph unless you also add fill=NA to panel.border :

    theme(panel.border = element_rect(fill = NA, colour = "black"))
    

    One can also use:

    theme(panel.background = element_rect(fill = NA, color = "black")
    

    source (section "Panel Attributes")

    0 讨论(0)
  • 2020-12-13 05:27

    You can try:

     strip.background = element_rect(colour=NA, fill=NA),
     panel.border = element_rect(fill = NA, color = "black"))
    
    0 讨论(0)
提交回复
热议问题