【问题标题】:Place a grey box around chart title in ggplot2在ggplot2中的图表标题周围放置一个灰色框
【发布时间】:2017-08-25 21:17:54
【问题描述】:

当我们在 ggplot 中使用 facet 选项时,我们会在标题 (3,4,5) 周围看到一个漂亮的灰色框。

library(ggplot2)

data(mtcars)

ggplot(mtcars, aes(cyl)) + geom_bar() + facet_wrap(~gear) + theme_bw()

当我们不使用facet 选项时,如何在图表标题周围放置一个类似的灰色框?

ggplot(mtcars, aes(cyl)) + geom_bar() + theme_bw() +
  ggtitle("How do you put a grey box around me??")

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    由于您要问的是如何在没有方面的情况下进行操作,严格来说这不是一个答案,而只是指出这一点,一种快速而肮脏的方法是“欺骗”并毕竟使用方面。例如,

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

    成功了。

    【讨论】:

    • 伟大的作弊。将尝试更频繁地使用它。 :p
    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2017-01-02
    • 2021-05-31
    • 2011-01-22
    • 2018-10-04
    相关资源
    最近更新 更多