简体   繁体   中英

Frequency count of dates

I have a data frame with a column of dates. I am trying to get a frequency count of each date. I was thinking that a histogram would visualize the data nicely, but maybe there is a better way? I was able to created a histogram of the data but it is not exactly what I was looking for. I was hoping to get each individual date on the x-axis and the frequency count on the y-axis.

I have done some programming in R but I have not done much visualizations in R. Any help would be greatly appreciated.

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")

Here a simple ggplot2 solution:

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))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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