My tsibble 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")
Preparing the df:
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 hourly data in this manner:
df %>% gg_season(total, period = "day")
Of course I cant, because the “yrweek” column in my df is not of hourly granularity.
How to tackle this please? How to convert the “yrweek” column to the format that it can be plotted using feasts::gg_season() function?
Many thanks in advance.