【问题标题】:Can we change the color of the region around the plot using ggplot2 in R?我们可以使用 R 中的 ggplot2 更改绘图周围区域的颜色吗?
【发布时间】:2018-11-21 18:43:20
【问题描述】:

我想从 R 中的 excel 复制一个图表。为此,我必须创建一个图表,其中图表的所有边框区域都被着色,如下所示:

我尝试了很多方法,也搜索了很多,但没有结果。

这是我在复制图表时达到的最佳效果:

请帮忙。

谢谢

【问题讨论】:

  • “边境地区”是什么意思?您的问题不清楚。

标签: r ggplot2


【解决方案1】:

听起来您想更改 ggplot 的主题。很多选项under the hood。这是执行您所描述的基本示例:

set.seed(42)
example <- data.frame(x = 1:100, value = rnorm(100))


library(ggplot2)
ggplot(example, aes(x, value)) + 
  geom_line() +

  # here's where we set the appearance of the theme
  #  For more:  https://ggplot2.tidyverse.org/reference/theme.html
  theme(plot.background = element_rect(fill = "gray75"), # region outside plot
        panel.background = element_rect(fill = "white"), # region inside plot
        panel.grid = element_line(color = "gray90"))     # bring back gridlines

【讨论】:

    猜你喜欢
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    相关资源
    最近更新 更多