Hi all, I am just curious how to sort the groups in a categorical box plot chart bwplot here is the example: d<-data.frame(sample(rep(month.abb,20), 100), runif(100,1,10)); colnames(d) <- c("Month", "Value"); bwplot(d$Month ~ d$Value); as you can see Months are not sorted alphabetically. Does anybody know ho to sort those on the chart level? Thank you Jan [[alternative HTML version deleted]]
Hi make Month factor, sort its levels and do bwplot as you did ?factor ?levels Regards Petr r-help-bounces at r-project.org napsal dne 27.08.2010 15:03:06:> Hi all, > > I am just curious how to sort the groups in a categorical box plot chart > bwplot > > here is the example: > > d<-data.frame(sample(rep(month.abb,20), 100), runif(100,1,10)); > colnames(d) <- c("Month", "Value"); > bwplot(d$Month ~ d$Value); > > as you can see Months are not sorted alphabetically. Does anybody knowho to> sort those on the chart level? > > Thank you > Jan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On Aug 27, 2010, at 3:03 PM, Jan Hornych wrote:> Hi all, > > I am just curious how to sort the groups in a categorical box plot chart > bwplot > > here is the example: > > d<-data.frame(sample(rep(month.abb,20), 100), runif(100,1,10)); > colnames(d) <- c("Month", "Value"); > bwplot(d$Month ~ d$Value); > > as you can see Months are not sorted alphabetically. Does anybody know ho to > sort those on the chart level?Er, they seem to be alphabetically sorted alright: Apr, Aug, Dec, Feb,... Presumably you want the natural sorting, try d<-data.frame(sample(rep(factor(month.abb, levels=month.abb),20), 100), runif(100,1,10)); colnames(d) <- c("Month", "Value"); bwplot(d$Month ~ d$Value); or ...factor(1:12. labels=month.abb)... -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
On Aug 27, 2010, at 9:03 AM, Jan Hornych wrote:> Hi all, > > I am just curious how to sort the groups in a categorical box plot > chart > bwplot > > here is the example: > > d<-data.frame(sample(rep(month.abb,20), 100), runif(100,1,10)); > colnames(d) <- c("Month", "Value"); > bwplot(d$Month ~ d$Value); > > as you can see Months are not sorted alphabetically.But, they are sorted alphabetically on my device. I would have expected a request to get them sorted in calendar order, which can be accomplished by changing your dataframe construction to explicitly use a factor call (rather than the implicit one) allowing you to add a levels specification: d <- data.frame( mon=factor( sample(rep(month.abb,20), 100), levels=month.abb), runif(100,1,10)) And note that your superfluous ";"'s will mark you as a recovering SAS useR.> Does anybody know ho to > sort those on the chart level? > > Thank you > JanDavid Winsemius, MD West Hartford, CT > sessionInfo() R version 2.11.1 Patched (2010-06-14 r52281) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] tcltk splines stats graphics grDevices utils datasets methods base other attached packages: [1] np_0.40-3 cubature_1.0 boot_1.2-42 eha_1.2-18 [5] sqldf_0.3-5 chron_2.3-35 RSQLite.extfuns_0.0.1 RSQLite_0.9-2 [9] DBI_0.2-5 gsubfn_0.5-3 proto_0.3-8 WriteXLS_1.9.0 [13] rms_3.0-0 Hmisc_3.8-1 survival_2.35-8 plyr_1.0.2 [17] lattice_0.18-8 loaded via a namespace (and not attached): [1] cluster_1.12.3 grid_2.11.1 tools_2.11.1