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

标签 r ggplot2 aesthetics

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

# 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

最佳答案

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

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

enter image description here

关于r - 为什么我不能使用 override.aes 更改图例中的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33703417/

相关文章:

r - 考虑到位置为 ='dodge' 的条形,如何在柱形条形图上添加线条,其中线条经过条形的中顶部?

r - 如何在 ggplots 中维护配色方案,同时删除每个图中未使用的级别?

r - 使用字符串作为输入使用 dplyr 编程

r - 如何为 ggplot 绘图编写测试

R,在数据框中创建一个新列,该列应用具有相似名称的所有列的函数

r - 将 fiddle 图与森林图对齐

r - 使用 geom_hex 以编程方式查找比例填充范围

r - 使用 ggplot 为轴刻度标签的一部分动态着色

无法使用给定的 CA 证书对 R 和对等证书进行身份验证

r - 包含表达式的图例文本换行