Place a grey box around chart title in ggplot2

前端 未结 1 1300
忘掉有多难
忘掉有多难 2021-01-05 15:51

when we use the facet option in ggplot, we get a beautiful grey box around the headings (3,4,5).

library(ggplot2)

data(mtcars)

ggplot(mtcars,          


        
相关标签:
1条回答
  • 2021-01-05 16:55

    Since you are asking how to do it without facets, this is strictly speaking not an answer, but just to point it out, one quick and dirty way would be to "cheat" and to use a facet after all. For instance,

    mtcars$title <- "How do you put a grey box around me??"
    ggplot(mtcars, aes(cyl)) + geom_bar() + theme_bw() +
      facet_grid(. ~ title)
    

    does the trick.

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