简体   繁体   English

R-绘图日期不正确

[英]R- Plotly plot dates are out of order

I am making a plotly plot with this data from 538 . 我正在用538的数据绘制一个绘图。 The dates are organized but when I produce a plot (dates as x-axis), it starts with October, then November, then July, and then it's finally in order. 日期是有条理的,但是当我绘制一个图(日期为x轴)时,它从10月开始,然后是11月,然后是7月,最后是按顺序排列。

This is all I am doing for code right now. 这就是我现在为代码所做的全部。

plot_ly(weather, x = ~date, y = ~actual_min_temp)

Before plotting, make sure your date data is converted to a date class. 绘制之前,请确保您的日期数据已转换为日期类。 This error can happen when the date data is a character class instead, for example. 例如,当日期数据改为字符类时,可能会发生此错误。 To convert data to a date class, you can try using one of these: 要将数据转换为日期类,可以尝试使用以下方法之一:

weather <- as.Date(weather$date)

#or

weather <- as.POSIXct(weather$date)

Then try plotting again. 然后尝试再次绘图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM