Stéphane CRUVEILLER
2007-Dec-04 14:03 UTC
[R] Multiple stacked barplots on the same graph?
Dear R-Users, I would like to know whether it is possible to draw several stacked barplots (i.e. side by side on the same sheet)... my data look like : Cond1 Cond1' Cond2 Cond2' Compartment 1 11,81 2,05 12,49 0,70 Compartment 2 10,51 1,98 13,56 0,85 Compartment 3 1,95 0,63 2,81 0,22 Compartment 4 2,08 0,17 3,13 0,06 Compartment 5 2,51 0,20 4,58 0,03 ps: Cond1' values should be stacked on Cond1, Cond2' on Cond 2 and so on... and series 1 and 2 should be side by side for each compartement.... Thanks for any help. St?phane. -- "La science a certes quelques magnifiques r?ussites ? son actif mais ? tout prendre, je pr?f?re de loin ?tre heureux plut?t qu'avoir raison." D. Adams -- AGC website <http://www.genoscope.cns.fr/agc> St?phane CRUVEILLER Ph. D. Genoscope - Centre National de S?quencage Atelier de G?nomique Comparative 2, Rue Gaston Cremieux CP 5706 91057 Evry Cedex - France Phone: +33 (0)1 60 87 84 58 Fax: +33 (0)1 60 87 25 14 scruveil at genoscope.cns.fr
St?phane CRUVEILLER <scruveil <at> genoscope.cns.fr> writes:> I would like to know whether it is possible to draw several > stacked barplots (i.e. side by side on the same sheet)... > > my data look like : > > Cond1 Cond1' Cond2 Cond2' > Compartment 1 11,81 2,05 12,49 0,70 > Compartment 2 10,51 1,98 13,56 0,85 > Compartment 3 1,95 0,63 2,81 0,22 > Compartment 4 2,08 0,17 3,13 0,06 > Compartment 5 2,51 0,20 4,58 0,03 > > ps: Cond1' values should be stacked on Cond1, Cond2' on Cond 2 and so > on... and series 1 and 2 > should be side by side for each compartement....Check the following example on xyplot/lattice: barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), stack = TRUE, auto.key = list(points = FALSE, rectangles = TRUE, space = "right"), ylab = "Barley Yield (bushels/acre)", scales = list(x = list(rot = 45))) You have to reformat your data to the long format first for this, e.g. by using reshape. Comp Cond x 1 1 11.81 1 2 2.05 With allow.multiple=TRUE, it might be possible to avoid the reformatting, but I never have used that form, because I the "long" had many advantages. Dieter
Perhaps this could be useful: > x=scan() 11.81 10.51 1.95 2.08 2.51 2.05 1.98 0.63 0.17 0.20 12.49 13.56 2.81 3.13 4.58 0.70 0.85 0.22 0.06 0.03 > x=matrix(x,5,4,byrow=T) > rownames(x)=paste("comp",1:5,sep="") > colnames(x)=paste("c",1:4,sep="") > library(ggplot2) > dfm=melt(x) > qplot(as.factor(x=X1),y=value,geom="histogram",data=dfm,fill=X2) domenico vistocco St?phane CRUVEILLER wrote:> Dear R-Users, > > I would like to know whether it is possible to draw several > stacked barplots (i.e. side by side on the same sheet)... > > > my data look like : > > Cond1 Cond1' Cond2 Cond2' > Compartment 1 11,81 2,05 12,49 0,70 > Compartment 2 10,51 1,98 13,56 0,85 > Compartment 3 1,95 0,63 2,81 0,22 > Compartment 4 2,08 0,17 3,13 0,06 > Compartment 5 2,51 0,20 4,58 0,03 > > ps: Cond1' values should be stacked on Cond1, Cond2' on Cond 2 and so > on... and series 1 and 2 > should be side by side for each compartement.... > > Thanks for any help. > > St?phane. > >