Modify Legend using ggplot2 in R

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! ![Histogram With Overlay][1] [1]: http://i.stack.imgur.com/7neAx.png
also check out geom_density(). Easier than stat_function(...) IMHO.

以上就是Modify Legend using ggplot2 in R的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏