reorder() no longer functioning as expected

22 views
Skip to first unread message

Brandon Bertelsen

unread,
Jun 22, 2012, 3:15:48 PM6/22/12
to ggp...@googlegroups.com
In previous versions - I used to use reorder(x,y) in the aesthetic to reorder factor variable (x) by some numeric column (y). This no longer seems to function. 

When using coord_flip(), I used to be able to cheat, with something like reorder(x,-as.numeric(dat$x)) to ensure that the flip kept the factors in my preferred order. But this doesn't seem to work anymore. 

Can anyone show me how to maintain the original factor order when using coord_flip() and also, speak to what's happened to the functionality available in reorder()?

Winston Chang

unread,
Jun 22, 2012, 3:37:00 PM6/22/12
to Brandon Bertelsen, ggp...@googlegroups.com
I don't know about reorder(), but you can add something like:
  scale_x_continuous(limits = rev(levels(dat$x)))

-Winston


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Dennis Murphy

unread,
Jun 22, 2012, 4:32:06 PM6/22/12
to Brandon Bertelsen, ggp...@googlegroups.com
I think we'll need a reproducible example from you because the
following example from the ggplot2 book (p. 124) seems to work for me:

mpg2 <- subset(mpg, cyl != 5 & drv %in% c('4', 'f'))
mpg3 <- within(mpg2, {
model <- reorder(model, cty)
manufacturer <- reorder(manufacturer, -cty)
} )
qplot(cty, model, data = mpg3)
qplot(cty, model, data = mpg3) + coord_flip() +
opts(axis.text.x = theme_text(angle = 90))

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] plyr_1.7.1 reshape2_1.2.1 scales_0.2.1 deldir_0.0-19 MSG_0.2
[6] proto_0.3-9.2 ggplot2_0.9.1

loaded via a namespace (and not attached):
[1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 labeling_0.1
[5] MASS_7.3-18 memoise_0.1 munsell_0.3 RColorBrewer_1.0-5
[9] stringr_0.6 tools_2.15.0

Dennis
Reply all
Reply to author
Forward
0 new messages