【问题标题】:Change the default colours used by geom_rect in ggplot2更改 ggplot2 中 geom_rect 使用的默认颜色
【发布时间】:2018-09-13 18:51:29
【问题描述】:

我使用 geom_rect 突出显示我的点图图的 4 个单独部分,ggplot2 使用默认的粉色、绿色、蓝色和紫色在矩形中着色,有人知道更改这些默认颜色的方法吗?

我没有为一个可行的例子而烦恼,但如果你想要一个,请告诉我,我可以在 cmets 中发布

【问题讨论】:

  • 不关心一个可行的例子是吸引反对票的好方法。始终包含一个
  • @MikeyHarper 感谢您的建议,即使我遇到了这个问题,在互联网上搜索了几个小时后,我才使用 R 大约一个星期左右我不会认为它是我需要的答案,因为我不知道我在寻找什么,因此我问自己的问题

标签: r ggplot2


【解决方案1】:

使用scale_fill_manual。一个例子:

library('ggplot2')  #v 0.9.0
library('scales')
(unemp <- qplot(date, unemploy, data=economics, geom="line", 
                 xlab = "", ylab = "No. unemployed (1000s)"))

presidential <- presidential[-(1:3), ]

yrng <- range(economics$unemploy)
xrng <- range(economics$date)
unemp + geom_vline(aes(xintercept = start), data = presidential)
unemp + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party),
                   ymin = yrng[1], ymax = yrng[2],
                   data = presidential) + 
         scale_fill_manual(values = alpha(c("blue", "red"), 0.2))

更多: How can I have two different scale_fill_manual active in a ggplot command

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2021-01-16
    • 1970-01-01
    相关资源
    最近更新 更多