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.

Reply via email to