[R] ggplot-How to define fill colours?

From: Pedro de Barros <pbarros_at_ualg.pt>
Date: Mon, 17 Dec 2007 22:54:47 +0000


Dear R's (most likely Hadley),

I want to build a stacked bar plot where I would like to define which colours will be used for each of the groups. However, I do not seem to find a way to do this, even if I've been looking over many places.

I have tried several variations, and my final try was this code, but I still do not manage to get the colours as I pre-define. Any hints about how to get this?

Thanks in advance,
Pedro



my code:
>plotdata1<-data.frame(x=rep(factor(1:4),4), y=rep(0.1*(1:4),4),
+group=as.character(rep(c('white', 'red', 'blue', 'green'),rep(4,4))))
>plot0<-ggplot()
>plot3<-plot0+layer(data=plotdata1, mapping=aes_string(x='x',y='y',

+fill='group'),geom='bar', stat='identity', position='stack')
>print(plot3)


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 18 Dec 2007 - 08:35:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Dec 2007 - 11:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.