【问题标题】:how to make histogram with dates in format aaaa-mm-dd in R如何在R中以aaaa-mm-dd格式制作日期直方图
【发布时间】:2020-12-22 08:08:55
【问题描述】:

我有一个包含烧花日期的数据库。我想用这个日期制作一个直方图,想验证比如最火燃烧的月份。

我的日期:2010/09/21 2010/09/21 2010/09/21 2010/09/21 2010/09/21 2010/09/21 2010/09/21 2010/10/18 2011/07/08 2011/07/08 2011/07/09 2011/07/09 2011/08/06 2011/08/13 2011/08/16 2011/08/16 2011/08/31 2011/08/31 2011/09/13 2011/09/13 2011/09/13 2011/09/13 2012/09/10 2012/09/08 2012/10/01 2012/11/22 2013/02/19 2013/03/05 2013/08/03 2013/08/14 2014/08/20 2013/09/13 2015/03/16 2015/03/14 2015/08/13 2020/04/11 2020/04/18 2020/04/18 2020/04/22 2020/04/22 2020/04/23 2020/04/23 2020/04/23 2020/04/27 2020/04/27 2020/04/27 2020/04/29 2020/04/29 2020/05/11 2020/04/28 2020/04/28 2020/06/12 2020/06/12 2020/06/12 2020/06/12 2020/08/11 2020/08/15 2020/08/15 2020/08/15 2020/08/29 2020/08/29 2020/08/29 2020/08/29 2015/10/19 2017/09/10 2018/03/23 2018/06/24 2018/09/11 2018/11/11 2018/11/11 2019/02/06 2019/02/22 2019/03/12 2019/04/14 2019/07/31 2019/07/31 2019/07/31 2016/11/06 2017/07/13 2017/07/13 2017/07/13 2017/07/24 2017/07/24 2017/08/30 2017/08/30 2017/08/30 2017/08/30 2017/03/25

【问题讨论】:

  • 您确定要使用直方图吗?每个月的条形图对你有用吗?例如:barplot(table(format(as.Date(x), "%Y-%m")), las=2)?
  • 是的,我需要 2010 年到 2020 年之间的直方图。

标签: r date histogram


【解决方案1】:

有一个hist.Date 方法。

hist(as.Date(d), breaks="months", xlab="Date", main="Forestal burn")


示例数据:

d <- c("2010/09/21", "2010/09/21", "2010/09/21", "2010/09/21", "2010/09/21", 
"2010/09/21", "2010/09/21", "2010/10/18", "2011/07/08", "2011/07/08", 
"2011/07/09", "2011/07/09", "2011/08/06", "2011/08/13", "2011/08/16", 
"2011/08/16", "2011/08/31", "2011/08/31", "2011/09/13", "2011/09/13", 
"2011/09/13", "2011/09/13", "2012/09/10", "2012/09/08", "2012/10/01", 
"2012/11/22", "2013/02/19", "2013/03/05", "2013/08/03", "2013/08/14", 
"2014/08/20", "2013/09/13", "2015/03/16", "2015/03/14", "2015/08/13", 
"2020/04/11", "2020/04/18", "2020/04/18", "2020/04/22", "2020/04/22", 
"2020/04/23", "2020/04/23", "2020/04/23", "2020/04/27", "2020/04/27", 
"2020/04/27", "2020/04/29", "2020/04/29", "2020/05/11", "2020/04/28", 
"2020/04/28", "2020/06/12", "2020/06/12", "2020/06/12", "2020/06/12", 
"2020/08/11", "2020/08/15", "2020/08/15", "2020/08/15", "2020/08/29", 
"2020/08/29", "2020/08/29", "2020/08/29", "2015/10/19", "2017/09/10", 
"2018/03/23", "2018/06/24", "2018/09/11", "2018/11/11", "2018/11/11", 
"2019/02/06", "2019/02/22", "2019/03/12", "2019/04/14", "2019/07/31", 
"2019/07/31", "2019/07/31", "2016/11/06", "2017/07/13", "2017/07/13", 
"2017/07/13", "2017/07/24", "2017/07/24", "2017/08/30", "2017/08/30", 
"2017/08/30", "2017/08/30", "2017/03/25")

【讨论】:

  • 您是如何设法组织“d”中的数据的?我是 R 的新手。
  • @wesleysc352 试试(v &lt;- unname(unlist(read.table(text="2010/09/21 2010/09/21 2010/09/21"))))。我的解决方案对您有何帮助?
  • 抱歉,我有一个包含许多日期的 csv 表,我将如何像您一样自动生成“d”?我对这件事很迷茫。
  • 不错的答案。将 x 轴格式化为月-年可能会更清晰 - hist(as.Date(d), breaks="months", las=2, format="%m-%y")
  • @thelatemail 感谢您的指点,刚刚注意到format 参数,真的很酷!对于那些对所有论点感兴趣的人:运行?hist.Date。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
  • 2012-05-24
  • 2019-01-09
  • 2016-01-02
相关资源
最近更新 更多