I have been trying to label several variables in the same graph in ggplot. The following example clarifies the question:
df<-data.frame("a"=rnorm(100,150,30), "b"=rnorm(100,150,30),"c"=rnorm(100,150,30))
ggplot(data=df,aes())+geom_density(aes(x=a))+geom_density(aes(x=b))+geom_density(aes(x=c))
How do I assign the tag to the variables "a", "b", "c"? (please solve in the example)
Thanks
The truth is that I have a data frame with 108 variables and 242 thousand observations, the variables that I am going to plot are not in order, I can not use melt, my code is actually the following:
ggplot(data=DF, aes(x=DF$VAR60)) +
geom_density(aes(x=DF$VAR70), size=1) +
geom_density(aes(x=DF$VAR85), size=1)+
geom_density(aes(x=DF$VAR102), size=1)+
geom_density(aes(x=DF$VAR95), size=0.7)+
geom_density(aes(x=DF$VAR52), size=1)+
ggtitle("Distribución Pruebas Saber Pro")+geom_vline(xintercept = 150, size = 1.2, colour="grey")
I have NOT been able to assign the label or the legend to the graphic. Thanks for your collaboration