[R] Sorting groups in bwplot chart
peter dalgaard
pdalgd at gmail.com
Fri Aug 27 15:15:35 CEST 2010
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
More information about the R-help
mailing list