The answer to your question gets a bit into the philosophy of programming and
data storage. Is the order of levels of a factor a property of the plot? Or a
property of the factor/data itself?
Some programs see this as a property of the plot, so you specify the order at
the time you create the plot (and have to respecify it every time).
R/S sees this as a property of the data itself, so you should set the order when
creating your factor (or change it on the factor) before plotting, then every
time you plot (or other things) with this data, it automatically does the
correct thing. One way to change the order in your factor is:
> myfactor <- factor( myfactor,
levels=c('z','g','c','a') )
Or you can make a copy with a different name so that the original stays
unchanged (just plot using the new copy).
There are also functions with names like reorder and relevel in some packages
that may (or may not) be easier to use to reorder the levels of the factor.
Now, just plot like you did before and see what order the categories are plotted
in.
Hope this helps,
--
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 Louise Venne
> Sent: Friday, August 29, 2008 9:26 AM
> To: r-help at r-project.org
> Subject: [R] R graphical question
>
> I'm trying to create a graph using plot() with an axis that I
> essentially want to plot the categories in the reverse
> alphanumeric order - opposite of the typical R fashion. Is
> there a function to do this?
> In other words, I have categories "a", "c",
"g", "z" which is
> the order they'll be plotted, but I want to plot them as "z",
> "g","c","a".
> Thanks,
> Louise
>
>
> [[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 guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>