Hi, Is there a way to stack bars in a barchart as well as "beside" bars for the same treatment? eg.... I have one barchart like this: bio<-matrix(c(10,23,9,25),nrow=2,byrow=T) ntreat<-c("n0","n96") colnames(bio)<-ntreat barplot(bio,beside=T) now i want a similar barchart but with stacked bars: ld<-matrix(c(25,25,50,10,30,60,15,35,50,30,30,40),nrow=4,byrow=T) ntreat2<-c("n0","n96","n0","n96") rownames(ld)<-ntreat2 typ<-c("gr","fo","le") colnames(ld)<-typ barplot(t(ld)) I can't work out how to put the same treatments side by side and keep "typ" stacked. Thanks, Chris -- View this message in context: http://n4.nabble.com/barchart-with-stacked-and-beside-bars-tp1018374p1018374.html Sent from the R help mailing list archive at Nabble.com.
I don't understand what you are looking for. The line barplot(t(ld)) is placing the four treatments side by side, and is also stacking the three values of typ. Please indicate what you would like the figure to look like. Rich
I want n0 side by side then a gap and then n96 like in the first script "barplot(bio,beside=T)" I have done it in Excel but I had to put in some artifical zeros to produce the gap and i will have to change the axis labels, but i was wondering if there was a neater way of doing it in R http://n4.nabble.com/file/n1049632/graph%2Bexample.png -- View this message in context: http://n4.nabble.com/barchart-with-stacked-and-beside-bars-tp1018374p1049632.html Sent from the R help mailing list archive at Nabble.com.
## There are at least two options, one using mosaic and the other using barchart. ## Here are both. ## this is your data ld<-matrix(c(25,25,50,10,30,60,15,35,50,30,30,40),nrow=4,byrow=T) ntreat2<-c("n0","n96","n0","n96") rownames(ld)<-ntreat2 typ<-c("gr","fo","le") colnames(ld)<-typ ## now some rearrangements dim(ld) <- c(2,2,3) dimnames(ld) <- list(ntreat2=c("n0","n96"), rep=c(1,2), typ=c("gr","fo","le")) ld.df <- as.data.frame.table(ld) require(vcd) mosaic(ld, direction=c("v","v","h"), highlighting="typ") require(lattice) barchart(Freq ~ rep|ntreat2, group=typ, data=ld.df, origin=0, stack=TRUE) ## both mosaic and barchart have many arguments that you can use for ## finer control of the appearance.
Possibly Parallel Threads
- low-variance warning in lmer
- Theora player for Nokia Series 60
- [Bug 28212] New: image corruption
- write values of points beside points in plot
- Why did Martin save beside all the plotters? We can't kick iterations unless Ophelia will admiringly facilitate afterwards.