我正在使用ggplot软件包绘制N(0,1)密度叠加的正常变量直方图。我对这个软件包很陌生,我使用的代码是在R中使用ggplot2修改图例
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())
此代码产生下图。如何更改图例,以便将代表直方图的线替换为填充的蓝色框(代表直方图的条)?谢谢!
也检出'geom_density()'。比'stat_function(...)更容易'恕我直言。 – Chase