ggplot2 X变量的顺序不正确

时间:2017-08-31 17:25:43

标签: r ggplot2

此代码将X变量排序为< 8,10-12,12-20,20 +,然后是8-10。 为什么" 8-10"乱了?谢谢。

=RADIANS(brng)
`where brng is a named cells holding an angle measured in degrees

1 个答案:

答案 0 :(得分:0)

您应该使用有序的factor

mylevels <-c("<8", "8-10","10-12", "12-20","20+")
tst1 <- data.frame(
  len = c(1.00, 1.038219, 1.040130, 1.078980, 1.186618 ),
  pm25=factor(mylevels, levels=mylevels, ordered =T))


plottst1 <- ggplot(tst1, aes(x=pm25, y=len))
plottst1