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]:
also check out geom_density(). Easier than stat_function(...) IMHO.

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

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

评论 抢沙发

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

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