avoid colored box in legend

Viewed 44

How to avoid colored box in legend? I would just like it to be Line1 and Line2 without the box.

library(ggplot2)
ggplot(diamonds, aes(x=depth)) +
  geom_density(aes(color = "Line1"))+
  geom_function(fun=function(x) 
    dnorm(x, 
          mean=mean(diamonds$depth),
          sd=sd(diamonds$depth)),
    aes(color="Line2"))+
  scale_color_manual(" ", values=c(Line1="green", Line2="red"))

Thank you!

1 Answers

This could be acieved by adding option show.legend = FALSE to geom_density:

library(ggplot2)
ggplot(diamonds, aes(x=depth)) +
  geom_density(aes(color = "Line1"), show.legend = FALSE)+
  geom_function(fun=function(x) 
    dnorm(x, 
          mean=mean(diamonds$depth),
          sd=sd(diamonds$depth)),
    aes(color="Line2"))+
  scale_color_manual(" ", values=c(Line1="green", Line2="red"))

Related