Here is a piece of ggplot2 code plotting a set of 4 densities from samples:
library('reshape')
library('ggplot2')
data <- matrix(0,5,100)
for(i in seq(1,5,1)){
data[i,] <- rnorm(100,i,1)
}
df <- data.frame(melt(data))
g <- ggplot(data=df, aes(x=value,group=X1)) +
geom_density(fill="blue",alpha=0.5)
g
I would like to add the "index" of the density at the top of each of them. I tried many things including:
g + geom_text(aes(label=X1,y=0.5,group=X1));
Which does not give me what I expect but the index of the densities for each sample (as it was ignoring the "group" argument). I am surely missing something but what?