I am generating a histogram from 3 randomly generated vectors and then I generate a dataframe concatenating the vectors and add a key for each one ("a", "b" and "c") but the legend is not shown in the graph.
SAg_exp = rexp(cenarios,1/lambda)
SAg_unif= runif(cenarios,0,1)
normal= rnorm(cenarios,0,1)
dat <- data.frame(xx = c(SAg_exp,SAg_unif,normal),yy = rep(letters[1:3],each = cenarios))
graph = ggplot(dat, aes(x=xx)) +
geom_histogram(data=subset(dat,yy == 'a'),fill = "red",aes(fill=yy),alpha = 0.2) +
geom_histogram(data=subset(dat,yy == 'b'),fill = "blue",aes(fill=yy),alpha = 0.2) +
geom_histogram(data=subset(dat,yy == 'c'),fill = "green",aes(fill=yy),alpha = 0.2) +
ggtitle(paste("Histograma SAg:",tamanho,"apólices vs.",cenarios,"cenários")) +
ylab("Frequência") + xlab("SAg") +
scale_fill_manual(name="yy",values=c("a","b","c"),labels=c("Exponencial","Uniforme","Normal"))
print(graph)
So here is the generated graph, but without a legend.
Can someone help me? Thank you!