[R] Stacked barchart color

owenman solberg at speakeasy.net
Sat Jun 16 01:39:59 CEST 2007


Hi Hadley,
I tried your suggestion, using ggplot2, but I am still having a problem. The
final plot lacks the figure legend -- which it had before I added the 
scale_fill_identity()  bit.  Can  you see what I am doing wrong?  
(By the way, all I am trying to do is make the figure monochrome friendly. 
Is there an easy way to prepare ggplot graphics for a monochrom device?)
Thanks,Owen

> y$color = factor(y$Fnd)
> y$color = c("black","darkgray","lightgray","white") 
> y
      Fnd locus        Freq color
1  signeg     A 0.087248322     black
2     neg     A 0.711409396  darkgray
3     pos     A 0.201342282 lightgray
4  sigpos     A 0.000000000     white
5  signeg     C 0.320754717     black
6     neg     C 0.603773585  darkgray
7     pos     C 0.075471698 lightgray
8  sigpos     C 0.000000000     white
9  signeg     B 0.157534247     black
10    neg     B 0.732876712  darkgray
11    pos     B 0.109589041 lightgray
12 sigpos     B 0.000000000     white

> p = ggplot(y, aes(x=locus, y=Freq, fill=color)) +
> geom_bar(position="fill") + scale_fill_identity() 
> p



hadley wrote:
> 
> 
> Hi Dieter,
> 
> You can do this with ggplot2 (http://had.co.nz/ggplot2) as follows:
> 
> library(ggplot2)
> 
> barley1 <- subset(barley, site=="Grand Rapids" & variety %in%
> c("Velvet","Peatland"))
> barley1[] <- lapply(barley1, "[", drop=TRUE)
> 
> qplot(variety, yield, data=barley1, geom="bar", stat="identity",
> fill=factor(year))
> 
> barley1$fill <- c("red","green","blue","gray")
> qplot(variety, yield, data=barley1, geom="bar", stat="identity",
> fill=fill) + scale_fill_identity()
> 
> See http://had.co.nz/ggplot2/scale_identity.html and
> http://had.co.nz/ggplot2/position_stack.html for more details.
> 
> Hadley
> 
> 

-- 
View this message in context: http://www.nabble.com/Stacked-barchart-color-tf3909162.html#a11149419
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list