为什么我不能使用override.aes来更改图例中的颜色?

问题描述 投票:9回答:1

我想从ggplot的填充图例中删除颜色线。我通常使用guide_legend(override.aes = ...)来修改传奇美学 - 适用于点,线,alpha等,但它不适用于我的color美学。我究竟做错了什么?

# generate data
set.seed(47)
data = data.frame(year = rep(2000:2004, 3),
                  value = runif(15),
                  group = rep(c("A", "B", "C"), each = 5))

# create the plot
p = ggplot(data, aes(x = year, y = value, fill = group)) +
    geom_area(position = position_fill(), color = "white") +
    scale_fill_grey()

# this should modify the fill legend to remove the colored line
# but the line is still there
p + guides(fill = guide_legend(override.aes = list(color = NA)))

enter image description here

r ggplot2 aesthetics
1个回答
10
投票

这是colour需要与u拼写的情况之一。添加u使override.aes工作得很好。自2016年以来ggplot2发布已修复此错误,您可以使用任何拼写。

p + guides(fill = guide_legend(override.aes = list(colour = NA)))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.