[R] Sorting order of reorder with multiple variables
Deepayan Sarkar
deepayan.sarkar at gmail.com
Sat Aug 27 08:18:11 CEST 2011
On Thu, Aug 25, 2011 at 6:15 PM, markm0705 <markm0705 at gmail.com> wrote:
> I've been building a ranked dot plot for several days now and am sorting the
> data using the reorder command. What I don't understand is how reorder
> works when mutiple varibles are plotted by grouping. In the example below
> I'm using re-order to sort by a variable name Resv_Prop, but I'm plotting up
> to three different values of Resv_prop (different Year values) for each
> factor.
>
> The results are not what i expected and I would like to control the sorting
> by the 2010 Year values.
reorder() does have a FUN argument that let's you define a summary
measure that is used for sorting when multiple observations are
present per group. Unfortunately, this will not help you here.
However, once you realize that all you really need are the levels() of
your y-variable in the right order, you can finesse the problem as
follows:
Cal_dat_2010 <- subset(Cal_dat, Year == 2010)
tmp <- with(Cal_dat_2010, reorder(paste(Mine,Company), Resv_Prop))
with(Cal_dat,
dotplot(factor(paste(Mine,Company), levels = levels(tmp)) ~ Resv_Prop,
groups = factor(Year), auto.key = TRUE))
-Deepayan
More information about the R-help
mailing list