开发者

Changing color of density plots in ggplot2

I've got a nifty pair of probability density functions I created with ggplot2 as follows:

require(ggplot2)
set.seed(2)
data <- rbind( data.frame(type="a", lr=rnorm(100)), data.frame(type="b", lr=rnorm(100,.5,1.2)))
m <- ggplot(data, aes(x=lr)) 
m <- m + geom_density(aes(fill=factor(type)), size=2, alpha=.4) 
m

and that produces a nice plot:

Changing color of density plots in ggplot2

However I would really like that plot to have different color shading. I can't seem to figure it out. I thought the following would work:

开发者_运维问答
m + scale_colour_manual( values = c("red","blue"))

But no luck. I also tried passing fill colors to the geom_density() call, to no avail.

How do I change the fill colors?


Start kicking yourself:

m + scale_fill_manual( values = c("red","blue"))

Changing color of density plots in ggplot2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜