How to eliminate separate legend for geom_ribbon

You can merge both legends by giving the same name to both aesthetics, since you haven't provided a REPRoducible EXample (reprex) here is an example using the iris built-in dataset.

library(ggplot2)

ggplot(iris, aes(Petal.Length, Petal.Width, color = Species, fill = Species)) +
    geom_line() + 
    geom_ribbon(aes(ymin = Petal.Width -1, ymax = Petal.Width + 1), 
                alpha = .2) +
    theme(legend.position = "bottom") +
    labs(title = "Example",
         color = "Species", 
         fill = "Species")

Created on 2019-09-26 by the reprex package (v0.3.0)

1 Like