scale_fill_discrete和scale_fill_manual——图例选项混淆

28

我在应用两种不同的变化到我的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.

(分别它们都能正常工作)。怎么处理呢?

1个回答

49

您不需要将其加倍,这应该可行:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接