[R] mosaic row and column order
Achim Zeileis
Achim.Zeileis at wu-wien.ac.at
Wed Oct 31 22:51:21 CET 2007
On Wed, 31 Oct 2007, Duncan Murdoch wrote:
> On 31/10/2007 4:33 PM, Michael Kubovy wrote:
> > Dear R-helpers,
> >
> > I wasn't able to find out how to override the alphabetical ordering
> > of the rows and columns in a vcd::mosaic plot. I would like to have
> > them each ordered by numerical values in a different column of the
> > data frame that contains the contingency data.
> >
> > I would be most grateful for a pointer toward the solution.
>
> I don't know that particular function, but most functions in R treat the
> categorical variables as factors, and use the ordering of the factor
> levels in displays.
...and this is exactly what mosaic() in "vcd" does. Thanks for the
explanation, Duncan.
Z
> So you need to set this ordering explicitly, rather
> than let R do it automatically:
>
> #automatic gets alphabetical order
> > x <- factor(c("red", "green", "blue"))
> > x
> [1] red green blue
> Levels: blue green red
>
> #explicit gets whatever you want
> > x <- factor(c("red", "green", "blue"), levels=c("red", "green", "blue"))
> > x
> [1] red green blue
> Levels: red green blue
>
> Duncan Murdoch
>
> ______________________________________________
> 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.
>
>
More information about the R-help
mailing list