Skip to content
Back to formatted view

Raw Message

Message-ID: <20071218082810.3B2D5F8003@smtp3.ualg.pt>
Date: 2007-12-17T22:54:47Z
From: Pedro de Barros
Subject: ggplot-How to define fill colours?

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)