tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
528 stars 50 forks source link

How to group hourly data, aggregate them in weekly or monthly intervals and plot them with gg_season() #315

Open rcepka opened 3 weeks ago

rcepka commented 3 weeks ago

My dataset contains hourly data, which I want to aggregate on weekly basis and compute a hourly summary for specified variable. Then I would like to plot the data using gg_season(variable, period = "day")

  df <- pedestrian %>%     
    # Just simplifying data
    filter(lubridate::year(Date) == 2015 & Sensor == "Bourke Street Mall (North)") %>%    
    group_by(Time) %>%     
    index_by(yrweek = yearweek(Date_Time)) %>%     
    summarise(total = sum(Count)) %>%    
    arrange(yrweek, Time) 

  df
#> # A tsibble: 1,104 x 3 [1W]
#> # Key:       Time [24]
#>     Time   yrweek total
#>    <int>   <week> <int>
#>  1     0 2015 W08  2512
#>  2     1 2015 W08  2106
#>  3     2 2015 W08  1152
#>  4     3 2015 W08   899
#>  5     4 2015 W08   635
#>  6     5 2015 W08   492
#>  7     6 2015 W08   565
#>  8     7 2015 W08  1442
#>  9     8 2015 W08  3397
#> 10     9 2015 W08  4535
#> # ℹ 1,094 more rows

Created on 2024-08-19 with reprex v2.1.0

Now I would like to plot the data:

  df %>% gg_season(total, period = "hour")

How to do this please?