I’m currently using the ggplot package to plot a histogram of normal variates with a N(0, 1) density overlay. I’m very new to this package and the code I’m using is
x = rnorm(1000)
qplot(x, geom = 'blank') +
geom_histogram(aes(y = ..density.., colour = 'Histogram'), legend = FALSE,
binwidth = 0.5, fill = "blue") +
stat_function(fun = dnorm, aes(colour = 'Density'))+
scale_x_continuous('x', limits = c(-4, 4))+
opts(title = "Histogram with Overlay")+
scale_colour_manual(name = 'Legend', values = c('darkblue', 'red')) +
scale_y_continuous('Frequency')+
opts(legend.key=theme_rect(fill="white",colour="white"))+
opts(legend.background = theme_rect())
This code produces the following diagram. How do I change the legend so that the line representing the histogram is replaced with a filled blue box (that represents the bars of the histogram)? Thank You!

Maybe something like this…
Note: Since version 0.9.2
optshas been replaced bytheme. So for example, the last two lines above would be: