I'm trying to add a legend to a ggplot
of two histograms, that may overlap and therefore would like to have them slightly transparent:
library(ggplot2)
set.seed(1)
plot.df <- data.frame(x=c(rnorm(1000,30,1),rnorm(10000,40,5)),
group=c(rep("a",1000),rep("b",10000)))
using:
ggplot(plot.df,aes(x=x,fill=factor(group)))+
geom_histogram(data=subset(plot.df,group=='a'),fill="red",alpha=0.5)+
geom_histogram(data=subset(plot.df,group=='b'),fill="darkgray",alpha=0.5)+
scale_colour_manual(name="group",values=c("red","darkgray"),labels=c("a","b"))+scale_fill_manual(name="group",values=c("red","darkgray"),labels=c("a","b"))
but all I get is:
What's missing?