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)
ggplot-How to define fill colours?
3 messages · Pedro de Barros, ONKELINX, Thierry
Pedro, I've had a similar problem. See this post for the solution: http://thread.gmane.org/gmane.comp.lang.r.general/100649/focus=100673 Cheers, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -----Oorspronkelijk bericht----- Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens Pedro de Barros Verzonden: maandag 17 december 2007 23:55 Aan: r-help op stat.math.ethz.ch Onderwerp: [R] ggplot-How to define fill colours? Urgentie: Hoog 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 op 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.
Thanks Thierry, Rigth on target. Cheers, Pedro
At 10:35 2007/12/18, you wrote:
Pedro, I've had a similar problem. See this post for the solution: http://thread.gmane.org/gmane.comp.lang.r.general/100649/focus=100673 Cheers, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx at inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -----Oorspronkelijk bericht----- Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens Pedro de Barros Verzonden: maandag 17 december 2007 23:55 Aan: r-help at stat.math.ethz.ch Onderwerp: [R] ggplot-How to define fill colours? Urgentie: Hoog 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.