Hi, I have a barchart very similar to the example on the function documetation, however, I want to sort the bars according one group in one panel. Reminding: library(lattice) barchart(yield ~ variety | site, data = barley, groups = year, layout = c(1,6), ylab = "Barley Yield (bushels/acre)", auto.key=list(), scales = list(x = list(abbreviate = TRUE, minlength = 5))) I want to sort the yield value, in "waseca" site (e.g.), according the group of 1931. How can I do this??? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-sort-a-grouped-barchart-tp2133579p2133579.html Sent from the R help mailing list archive at Nabble.com.
On May 6, 2010, at 9:01 PM, LeandroTV wrote:> > Hi, > > I have a barchart very similar to the example on the function > documetation, > however, I want to sort the bars according one group in one panel. > > Reminding: > library(lattice) > barchart(yield ~ variety | site, data = barley, > groups = year, layout = c(1,6), > ylab = "Barley Yield (bushels/acre)", auto.key=list(), > scales = list(x = list(abbreviate = TRUE, > minlength = 5))) > > I want to sort the yield value, in "waseca" site (e.g.), according > the group > of 1931. How can I do this??? >You can reverse the year factor variable levels before plotting: barley$year.r <- factor(barley$year, levels=rev(levels(barley$year)) ) ... and then use the reversed factor. I don't think it would be fair to the reader to reverse the positions in just one panel. You did not say so but I suspect that you wanted to ask something along the lines of: sort the plotting order of the "variety" by the yield of the variety in one of the years, perhaps 1931? -- David> ml > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
See my recent reply under the subject "bar order using lattice barchart()" Running this code before doing your plot: barley$variety <- reorder(barley$variety, barley$yield, function(x) x[2] ) will cause the bars in all the plots to be reordered such that 1931 Waseca is increasing, is that what you wanted? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of LeandroTV > Sent: Thursday, May 06, 2010 7:01 PM > To: r-help at r-project.org > Subject: [R] How to sort a grouped barchart? > > > Hi, > > I have a barchart very similar to the example on the function > documetation, > however, I want to sort the bars according one group in one panel. > > Reminding: > library(lattice) > barchart(yield ~ variety | site, data = barley, > groups = year, layout = c(1,6), > ylab = "Barley Yield (bushels/acre)", auto.key=list(), > scales = list(x = list(abbreviate = TRUE, > minlength = 5))) > > I want to sort the yield value, in "waseca" site (e.g.), according the > group > of 1931. How can I do this??? > > Thanks > -- > View this message in context: http://r.789695.n4.nabble.com/How-to- > sort-a-grouped-barchart-tp2133579p2133579.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
Thanks for both. The reorder function works perfectly. -- View this message in context: http://r.789695.n4.nabble.com/How-to-sort-a-grouped-barchart-tp2133579p2164506.html Sent from the R help mailing list archive at Nabble.com.