11

I want to remove the color line from a fill legend for a ggplot. I usually use guide_legend(override.aes = ...) to modify legend aesthetics - works great for points, lines, alpha, etc., but it's not working for my color aesthetic. What am I doing wrong?

# 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

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294

1 Answers1

12

This was one of the cases where colour needed to be spelt with u. Adding the u made override.aes work just fine. ggplot2 releases since 2016 have fixed this bug, and you can use either spelling.

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

enter image description here

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 1
    Was banging my head on my desk quite hard over this issue when I wrote up [my seemingly simple answer](http://stackoverflow.com/questions/28694969/add-separate-legend-for-geom-vline/28696738#28696738) once... – Henrik Nov 14 '15 at 10:36