I have data frame that have date field. I need to create ggplot + geom_col that represent average amount by day for each hour (0-23)
I'm able to get total for every hour like this:
logs %>%
mutate(Hour = format(as.POSIXct(Date), format = "%H")) %>%
count(Hour) %>%
ggplot(aes(x = Hour, y = n)) + geom_col()
I need to get average values instead of totals. I found many questions about how to calculate average based on field, like this Calculate the mean by group, but I need to get average value based on items count. Example:
- id,date
- 1,2023-05-19 04:49:40
- 2,2023-05-18 04:49:40
- 3,2023-05-18 04:49:40
- 4,2023-05-18 04:49:40
Here I have 4 items for 04 o'clock, so in the plot I must see 3(May 18) + 1(May 19)/2(total days) = 2 value in 04 column, and so on for each hour