【问题标题】:CREATE A TIME SERIES PLOT in r with ggplot使用 ggplot 在 r 中创建时间序列图
【发布时间】:2022-08-14 15:12:01
【问题描述】:

我在大数据编码方面遇到问题。

查看(数据)

Year Month Deaths
1998 1 200
1998 2 40
1998 3 185
1998 4 402
1998 5 20
1998 6 48
1998 7 290
1998 8 15
1998 9 252
1998 10 409
1998 11 233
1998 12 122

我的数据一直到 2014 年。我想创建一个时间序列。在 x 轴上,5 年的步长中只有一些年份可用。在 y 轴上显示了 2000 年期间所有月份的死亡人数。我不知道我该如何编码?

    标签: r


    【解决方案1】:

    我不确定这是否正确,因为我没有任何数据。我从一本编程书中得到了这个

    data$date = as.Date(paste(data$Year, data$Month,1), format = "%Y %m %d")
    
    ggplot(data,
           aes(
             x = date,
             y = Deaths,
            )) +
      geom_line() +
      ggtitle("Time series") +
      xlab("Year") +
      ylab("Deaths")
    
    

    如果您想休息一个月,请更新,您可以使用

      scale_x_date(date_breaks = "Year", date_labels = "%Y", date_minor_breaks = "Month")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多