R ggplot2 X轴排序问题-字母顺序

我试图在ggplot中绘制数据,但是尽管我在aes()字段中使用了reorder命令,但x轴仍按字母顺序排序。

我已经尝试了在线上建议的大多数重新排序解决方案(由于数据融化,我的x轴似乎无法成为一个因素),而且似乎都无法正常工作。

(dff是一个熔化的数据帧)

ggplot(dff,aes(x = fct_reorder(dff$odname,dff$stop_sequence),y = dff$value,color = variable,group = variable)) + 
  geom_line(aes(x = fct_reorder(dff$odname,dff$stop_sequence))) +
  scale_y_continuous(limits = c(-5,10.5)) +
  theme(axis.text.x=element_text(angle=90,hjust=1)) + 
  labs(color="Comparisons\n") +
  xlab("Station Pair") +
  ylab("Time (mins)") + 
  ggtitle(paste("Schedule adherence on",target_route,"in date range",datemin,"-",datemax))

我所拥有的:

Insert commas into number string

我想要什么:

https://i.imgur.com/sUCC1mP.png

工作代码的代码(是的,我确实在损坏的示例中尝试使用reorder():

ggplot(dfTotal,aes(x = reorder(dfTotal$odname,stop_sequence),y = dfTotal$value,group = variable)) + 
  geom_line(lwd =.75) +
  scale_y_continuous(limits = c(0.5,1.5)) +
  theme(axis.text.x=element_text(angle=90,hjust=1)) + 
  labs(color="Time Comparisons\n") +
  xlab("Station Pair") +
  ylab("Peak/Midday") +
  ggtitle(paste("Peak/midday runtime ratios on",ROUTES,datemax))

怎么了?在此先感谢!

colin2625 回答:R ggplot2 X轴排序问题-字母顺序

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162837.html

大家都在问