I want to plot several densities, where the legend should reveal the parameters for each density function. Unfortunately, ggplot2
does not include the legend (which is weird, in the tutorial it did...)
Generate data:
x <- seq(from=-5, to=5, by=0.1)
y1 = dlaplace(x,0,0.5)
y2 = dlaplace(x,0,1)
y3 = dlaplace(x,0,2)
df = data.frame(x,y1,y2,y3)
Plot
ggplot(data=df, aes(x=x))+
geom_line(data= df, aes(y=y1), color="red")+
geom_line(data= df,aes(y=y2), color="blue")+
geom_line(data= df,aes(y=y3), color="green")+
ggtitle("Gamma distribution density function") +ylab("density")+ xlab("x")+
theme(legend.position = "bottom")+
guides(fill = guide_legend(reverse=TRUE))
I am new to ggplot
, and the following threads seemed related but unfortunately did not help me solve it (here and here)