I'd like to make a ggplot that includes unused levels in the legend:
df <- data.frame(x = 1:3,
y = 1:3,
z = factor(letters[1:3], levels = letters[1:4]))
ggplot(data = df) +
geom_point(aes(x=x, y=y, color = z)) +
scale_color_manual(drop = FALSE,
values = c(a = "red",
b = "blue",
c = "yellow",
d = "green"))
This produces:
However, I'd like to see a "green" dot next to "d" in the legend. Is there a way to do that without basically making the whole thing manually with override.aes?