【问题标题】:scale_fill_discrete and scale_fill_manual - legend options confusionscale_fill_discrete 和 scale_fill_manual - 图例选项混淆
【发布时间】:2014-09-30 08:00:43
【问题描述】:

在我的ggplot2 对象上应用两个不同的更改时遇到问题。我有一个带有 3 个组的条形图。我想:

  1. 为每个组设置颜色
  2. 重新排列图例标签的顺序

针对上述问题,我找到了以下解决方案:

  1. + scale_fill_manual(values = c("red", "green", "blue"))
  2. + scale_fill_discrete(guide = guide_legend(reverse=TRUE))

问题是第二个应用程序 (+ scale_fill_discrete(...)) 覆盖了第一个应用程序:

Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.

(分别它们都可以正常工作)。如何处理?

【问题讨论】:

    标签: r colors plot ggplot2 scale


    【解决方案1】:

    你不需要把它加倍,这应该可以工作:

    scale_fill_manual(values = c("red", "green", "blue"), name = "My name", 
                      guide = guide_legend(reverse = TRUE))
    

    【讨论】:

      猜你喜欢
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多