我有点问题。我曾经使用这种方法快速重新排序因子以使用 ggplot2 进行绘图。但它似乎不起作用:
tmp <- data.frame(Letters=letters[1:26],values=rnorm(26))
tmp <- transform(tmp, Letters = reorder(Letters,values))
identical(levels(tmp$Letters),letters[1:26]) # True! but shouldn't it be reorderd?
这里发生了什么?
会话信息()
R version 2.15.2 (2012-10-26)
Platform: i686-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] tools stats graphics grDevices utils methods base
other attached packages:
[1] reshape_0.8.4 digest_0.5.2 plyr_1.7.1 ggplot2_0.9.2.1
loaded via a namespace (and not attached):
[1] brew_1.0-6 colorspace_1.2-0 dichromat_1.2-4 evaluate_0.4.2 grid_2.15.2
[6] gtable_0.1.1 gtools_2.7.0 httr_0.2 labeling_0.1 MASS_7.3-22
[11] memoise_0.1 munsell_0.4 parallel_2.15.2 proto_0.3-9.2 RColorBrewer_1.0-5
[16] RCurl_1.95-1.1 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 whisker_0.1