这个问题在这里已有答案:
我正在尝试使用ggplot创建一个条形图 . 条形图很好但条形码按字典顺序排列,没有意义 . 样本数据框是年龄栏如下
Levels: 0-4 10 11 12 13 14 15 16 17 18 19 20-24 25-29 30-34 35-59 5 6 60+ 7 8 9 Age not stated All ages
当我用ggplot(m2,aes(x = reorder(年龄),y =值,fill =变量)绘图时)geom_bar(stat =“identity”)
我得到下面的情节
x轴上的Age按字典顺序排列 . 所以5,6,7,8,9在10,11等的右边 .
怎么解决这个问题?
1 回答
你需要将年龄变量重构为你希望ggplot绘制的顺序
其中“..1st ..”是第一个年龄段/标签