[R] Sorting problem
Gabor Grothendieck
ggrothendieck at myway.com
Fri Dec 24 14:22:02 CET 2004
> page took 6.48 seconds  home | my page | my email
> .
>
>
>
>
>
> email
>
>
>
>
> Mail Addresses Calendar Notepad ggrothendieck at myway.com sign out
> << Hide Folders Check Messages Compose Message POP Accounts | Mail Preferences | Help
>
>
> Folders
> Inbox
> Drafts
> Sent
> Trash (Empty)
> Bulk Mail (Empty)
>
>
>
> My Folders edit
> R
> Rcom
> Rtmp
> Saved
> this
> Tx
> wcd
> zoo
>
>
>
> Spam Tools info
> Spam Filter Level:
> OffLowMediumMedium-highHigh
> My Block List
> Image Filter
> Custom Filters
>
>
>
>
>
>
> Now Live:
>
> 125MB Free Storage Upgrade
>
>
>
>
> Send/Receive 10MB emails!
>
>
>
>
> < Prev Next > Back to Inbox Print View Full Header
>
> As AttachmentAs Inline Text Move to Folder----- Folders ------InboxDraftsSentTrashBulk Mail---- My Folders ----RRcomRtmpSavedthisTxwcdzoo
>
>
>
> Message is not flagged. [ Flag for Follow Up ]
>
> From: Gabor Grothendieck <ggrothendieck at myway.com>
>
> > From: <Ted.Harding at nessie.mcc.ac.uk>
> >
> > On 24-Dec-04 Gabor Grothendieck wrote:
> > >
> > > From: Paul JH Drake <p.drake at beatson.gla.ac.uk>
> > >>
> > >> When I plot data as a boxplot, the boxes appear on the plot in
> > >> alphabetical order (of group) rather than the order in which they
> > >> appear
> > >> in the data. So far, the only thing I can do to fix this is to prefix
> > >> the group labels with a,b,c...etc to trick R into plotting them in the
> > >> right order.
> > >>
> > >> Can sorting be turned off?
> > >> How should I address this sensibly?
> > >
> > > Actually they are shown in order of the levels of the factor.
> > > e.g. to show them in reverse order:
> > >
> > > attach(InsectSprays)
> > > spray <- factor( as.character(spray), level = rev(levels(spray)) )
> > > boxplot(count ~ spray)
> >
> > Applying boxplot to data constructed as follows:
> >
> > X<-list(C=rnorm(10),B=rnorm(20),A=rnorm(30))
> > boxplot(X)
> >
> > gives the plots in the order "C", "B", "A", so here they indeed
> > come out in the order of the data.
> >
> > But suppose I had wanted them in the order "B", "A", "C", say.
> > How would Gabor's suggestion (or similar) be applied to this case?
>
> boxplot(X[c("B","C","A")])
>
It occurred to me that maybe your question was not how to reorder
them if they are in list form but how to convert the list form
to the formula form. If that was it then:
Xu <- unlist(X)
g <- factor(rep(names(X), sapply(X, length)))
boxplot(Xu ~ g)
More information about the R-help
mailing list