频率计数日期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了频率计数日期相关的知识,希望对你有一定的参考价值。

我有一个包含日期列的数据框。我想获得每个日期的频率计数。我认为直方图可以很好地可视化数据,但也许有更好的方法?我能够创建数据的直方图,但这并不是我想要的。我希望在x轴上得到每个单独的日期,在y轴上得到频率计数。

我在R中做了一些编程但是我在R中没有做太多的可视化。任何帮助都会非常感激。

RawDates<- c("11/8/2017","12/6/2017","10/6/2017","12/6/2017","1/24/2018","9/5/2017","1/24/2018","2/21/2018","10/12/2017","1/22/2018","5/2/2018","1/24/2018","10/12/2017","1/22/2018","2/21/2018","5/2/2018","3/12/2018","5/3/2018","11/7/2017","12/5/2017","9/8/2017","10/6/2017","10/5/2017","11/3/2017","12/6/2017","2/21/2018","11/2/2017","12/5/2017","5/2/2018","1/24/2018","9/6/2017","11/2/2017","2/21/2018","5/2/2018","1/24/2018","11/8/2017","3/12/2018","5/3/2018","1/24/2018")
FormattedDates <- as.Date(RawDates, format = "%m/%d/%Y")

df <- data.frame(FormattedDates)

##This is whatI have already tried
hist(df$FormattedDates, "days", format = "%m/%d/%Y")
答案

这里有一个简单的ggplot2解决方案:

library(ggplot2)
library(scales)

ggplot(df) +
 geom_histogram(aes(x = FormattedDates)) +
 scale_x_date(labels = date_format("%m %d %Y"), date_breaks = "30 days") +
 theme(legend.position = "bottom",
       axis.text.x = element_text(angle = 45, hjust = 1))

enter image description here

以上是关于频率计数日期的主要内容,如果未能解决你的问题,请参考以下文章

Pandas - 最近 x 天的值的计数频率

常用python日期日志获取内容循环的代码片段

JS代码片段:一个日期离现在多久了

sql 日期转换代码片段 - Dato,120,konvertere

频率计和通用计数器的区别?

110,排序-计数排序