I want to place the legend of each histogram over its peak instead of the right of the figure in R. Let me explain it with a pseudo data set:
a <- rnorm(100, mean = 20, sd = 1)
b <- rnorm(100, mean = 22, sd = 1)
aleg <- rep("A",length(a))
bleg <- rep("B",length(b))
data <- data.frame(value=c(a,b), variable=c(lega,legb))
ggplot(data,aes(x=value, fill=variable)) + geom_density(alpha=0.25) + labs(fill="")
which gives you:
This is what I want:
I have a big data set that has ~8 different variables. That's why I want a quick solution instead of adding individual text boxes.
Thanks in advance!