[R] What determines the order of rows in a lattice barchart?

From: Geoff Russell <geoffrey.russell_at_gmail.com>
Date: Sat 28 Oct 2006 - 11:30:21 GMT


Hi,

What determines the order of the rows in a barchart?

Cheers,
Geoff.

Here is my code, and the data follows. If I have z in alpha order, the barchart is in
some order I can't determine. I originally tried rownames(twater)~twater$Cat, but the
chart wasn't in rownames(twater) order either.

library(lattice)
twater<-read.csv("totalwater.csv",strip.white=T) twater$Cat<-ordered(twater$Cat,levels=(sort(levels(twater$Cat)))) sel<-twater$Cat=="A"
nm<-sort(rownames(twater))
z<-factor(nm,levels=nm)
chart<-barchart(z~twater$Volume,

     xlab="Volume of Water '000 ML",
     main="Water Use In Australia for Food",
     scales=list(col='dark green',
          cex=1.2,
          fontface='bold',
     ),
     panel=function(x,y) {
          panel.barchart(x[!sel],y[!sel],col='blue')
          panel.barchart(x[sel],y[sel],col='red')
     })

pdf("Rplot-totalwater.pdf",height=4)
plot(chart)
dev.off()
               Volume,     Cat, Source
   Agriculture,   16660,       A,   WA
   Cotton,         2908,       A,   WA
   Rice,           1951,       A,   WA
   Sugar,          1388,       A,   BA
   Grapes,          729,       A,   WA
   Fruit&Veg,      1358,       A,   WA
   Household,      2181,       H,   WA
   Beef,           3229,       B,   BA
   Diary,          3542,       B,   BA

csv data:

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Sat Oct 28 21:41:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 28 Oct 2006 - 18:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.