I plotted histogram and kde's of a vector with ggplot in R. Now I'd like to add a legend containing the three kde plots --> "rectangular", "epanechnikov" and "gaussian". I just can't make it work!
v1 = data.frame(x=rnorm(500,30,9))
ggplot(data=v1, aes(x=x)) +
geom_histogram(binwidth=2, color="grey", fill="white") +
geom_density(aes(y=2 * ..count..), kernel="rectangular", color="orange") +
geom_density(aes(y=2 * ..count..), kernel="epanechnikov", color="red") +
geom_density(aes(y=2 * ..count..), kernel="gaussian", color="blue") +
scale_color_manual(labels=c("rectangular", "epanechnikov","gaussian"),
values=c("orange"="orange", "red"="red", "blue"="blue"))