【问题标题】:R- Plotly plot dates are out of orderR- Plotly 情节日期乱序
【发布时间】:2018-02-21 13:02:08
【问题描述】:

我正在用这个数据from 538 绘制一个情节图。日期是有组织的,但是当我制作一个图(日期为 x 轴)时,它从 10 月开始,然后是 11 月,然后是 7 月,最后是有序的。

这就是我现在为代码所做的一切。

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

【问题讨论】:

    标签: r date plot plotly


    【解决方案1】:

    在绘图之前,请确保您的日期数据已转换为日期类。例如,当日期数据是字符类时,可能会发生此错误。要将数据转换为日期类,您可以尝试使用以下方法之一:

    weather <- as.Date(weather$date)
    
    #or
    
    weather <- as.POSIXct(weather$date)
    

    然后再次尝试绘图。

    【讨论】:

    • 我试图这样做,但我认为我没有正确输入。非常感谢你!花了 2 多天的时间在这个天哪,但是谢谢你!!
    猜你喜欢
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    相关资源
    最近更新 更多