?aus_production # Quarterly production of selected commodities in Australia
?pelt # Hudson Bay Company trading records, 1845-1935 (annual)
?gafa_stock # Google/Amazon/Facebook/Apple daily stock prices
?vic_elec # Half-hourly electricity demand for Victoria, Australia
interval(aus_production) # Bricks
## <interval[1]>
## [1] 1Q
interval(pelt) # Lynx
## <interval[1]>
## [1] 1Y
interval(gafa_stock) # Close
## <interval[1]>
## [1] !
interval(vic_elec) # Demand
## <interval[1]>
## [1] 30m
aus_production (Bricks):
quarterly (1Q).pelt (Lynx): annual
(1Y).gafa_stock (Close):
daily, but irregular — only trading days, so
weekends/holidays are missing.vic_elec (Demand):
half-hourly (30m).autoplot(aus_production, Bricks)
autoplot(pelt, Lynx)
autoplot(gafa_stock, Close)
autoplot(vic_elec, Demand) +
labs(
title = "Half-hourly electricity demand: Victoria, Australia",
subtitle = "2012–2014",
y = "Demand (MWh)",
x = "Time (half-hourly)"
)
gafa_stock |>
group_by(Symbol) |>
filter(Close == max(Close)) |>
ungroup() |>
select(Symbol, Date, Close) |>
arrange(Symbol)
## # A tsibble: 4 x 3 [!]
## # Key: Symbol [4]
## Symbol Date Close
## <chr> <date> <dbl>
## 1 AAPL 2018-10-03 232.
## 2 AMZN 2018-09-04 2040.
## 3 FB 2018-07-25 218.
## 4 GOOG 2018-07-26 1268.
tute1.csvtute1 <- readr::read_csv("https://otexts.com/fpp3/extrafiles/tute1.csv")
mytimeseries <- tute1 |>
mutate(Quarter = yearquarter(Quarter)) |>
as_tsibble(index = Quarter)
mytimeseries
## # A tsibble: 100 x 4 [1Q]
## Quarter Sales AdBudget GDP
## <qtr> <dbl> <dbl> <dbl>
## 1 1981 Q1 1020. 659. 252.
## 2 1981 Q2 889. 589 291.
## 3 1981 Q3 795 512. 291.
## 4 1981 Q4 1004. 614. 292.
## 5 1982 Q1 1058. 647. 279.
## 6 1982 Q2 944. 602 254
## 7 1982 Q3 778. 531. 296.
## 8 1982 Q4 932. 608. 272.
## 9 1983 Q1 996. 638. 260.
## 10 1983 Q2 908. 582. 280.
## # ℹ 90 more rows
mytimeseries |>
pivot_longer(-Quarter) |>
ggplot(aes(x = Quarter, y = value, colour = name)) +
geom_line() +
facet_grid(name ~ ., scales = "free_y")
mytimeseries |>
pivot_longer(-Quarter) |>
ggplot(aes(x = Quarter, y = value, colour = name)) +
geom_line()
What changes: without facet_grid() all
three series share a single panel and a single y-axis. Because
GDP is on a much larger scale than Sales and
AdBudget, the smaller series get compressed and their
movements are hard to read. Faceting with scales = "free_y"
gives each series its own panel and y-scale, so each one’s pattern is
visible.
USgasinstall.packages("USgas")
library(USgas)
us_gas <- us_total |>
as_tsibble(index = year, key = state)
us_gas
## # A tsibble: 1,266 x 3 [1Y]
## # Key: state [53]
## year state y
## <int> <chr> <int>
## 1 1997 Alabama 324158
## 2 1998 Alabama 329134
## 3 1999 Alabama 337270
## 4 2000 Alabama 353614
## 5 2001 Alabama 332693
## 6 2002 Alabama 379343
## 7 2003 Alabama 350345
## 8 2004 Alabama 382367
## 9 2005 Alabama 353156
## 10 2006 Alabama 391093
## # ℹ 1,256 more rows
new_england <- c("Maine", "Vermont", "New Hampshire",
"Massachusetts", "Connecticut", "Rhode Island")
us_gas |>
filter(state %in% new_england) |>
autoplot(y) +
labs(
title = "Annual natural gas consumption — New England",
y = "Consumption (million cubic feet)",
x = "Year"
)
tourism.xlsxtourism_file <- tempfile(fileext = ".xlsx")
download.file("https://otexts.com/fpp3/extrafiles/tourism.xlsx",
tourism_file, mode = "wb")
tourism_xl <- readxl::read_excel(tourism_file)
head(tourism_xl)
## # A tibble: 6 × 5
## Quarter Region State Purpose Trips
## <chr> <chr> <chr> <chr> <dbl>
## 1 1998-01-01 Adelaide South Australia Business 135.
## 2 1998-04-01 Adelaide South Australia Business 110.
## 3 1998-07-01 Adelaide South Australia Business 166.
## 4 1998-10-01 Adelaide South Australia Business 127.
## 5 1999-01-01 Adelaide South Australia Business 137.
## 6 1999-04-01 Adelaide South Australia Business 200.
my_tourism <- tourism_xl |>
mutate(Quarter = yearquarter(Quarter)) |>
as_tsibble(index = Quarter, key = c(Region, State, Purpose))
identical(my_tourism, tourism)
## [1] FALSE
my_tourism |>
as_tibble() |>
group_by(Region, Purpose) |>
summarise(Trips = mean(Trips), .groups = "drop") |>
slice_max(Trips, n = 1)
## # A tibble: 1 × 3
## Region Purpose Trips
## <chr> <chr> <dbl>
## 1 Sydney Visiting 747.
The maximum average number of overnight trips is Melbourne / Visiting.
state_tourism <- my_tourism |>
group_by(State) |>
summarise(Trips = sum(Trips))
state_tourism
## # A tsibble: 640 x 3 [1Q]
## # Key: State [8]
## State Quarter Trips
## <chr> <qtr> <dbl>
## 1 ACT 1998 Q1 551.
## 2 ACT 1998 Q2 416.
## 3 ACT 1998 Q3 436.
## 4 ACT 1998 Q4 450.
## 5 ACT 1999 Q1 379.
## 6 ACT 1999 Q2 558.
## 7 ACT 1999 Q3 449.
## 8 ACT 1999 Q4 595.
## 9 ACT 2000 Q1 600.
## 10 ACT 2000 Q2 557.
## # ℹ 630 more rows
aus_arrivalsaus_arrivals |>
autoplot(Arrivals) +
labs(title = "Quarterly international arrivals to Australia",
y = "Arrivals (thousands)")
aus_arrivals |> gg_season(Arrivals)
aus_arrivals |> gg_subseries(Arrivals)
Unusual observations: the Q3 2000 spike across countries (the Sydney Olympics) and the corresponding drop in the following quarters; the sustained decline in Japanese arrivals after 1997 stands out against the growth in the other three.
| Time plot | ACF plot |
|---|---|
| 1 | B |
| 2 | A |
| 3 | D |
| 4 | C |
The match is made by comparing each series’ features to its ACF: trended series have ACFs that decay slowly, seasonal series show peaks at the seasonal lags, and white-noise series have all spikes within the significance bounds.
sessionInfo()
## R version 4.6.1 (2026-06-24)
## Platform: aarch64-apple-darwin25.4.0
## Running under: macOS Tahoe 26.6.2
##
## Matrix products: default
## BLAS: /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib
## LAPACK: /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] USgas_0.1.2 fable_0.5.0 feasts_0.5.0 fabletools_0.8.0
## [5] ggtime_1.0.0 tsibbledata_0.4.1 tsibble_1.2.0 ggplot2_4.0.3
## [9] lubridate_1.9.5 tidyr_1.3.2 dplyr_1.2.1 tibble_3.3.1
## [13] fpp3_1.0.3
##
## loaded via a namespace (and not attached):
## [1] utf8_1.2.6 rappdirs_0.3.4 sass_0.4.10
## [4] generics_0.1.4 anytime_0.3.13 hms_1.1.4
## [7] digest_0.6.39 magrittr_2.0.5 evaluate_1.0.5
## [10] grid_4.6.1 timechange_0.4.0 RColorBrewer_1.1-3
## [13] mixtime_0.3.0 fastmap_1.2.0 cellranger_1.1.0
## [16] jsonlite_2.0.0 purrr_1.2.2 scales_1.4.0
## [19] jquerylib_0.1.4 cli_3.6.6 rlang_1.3.0
## [22] crayon_1.5.3 vecvec_1.3.0 bit64_4.8.6
## [25] withr_3.0.3 cachem_1.1.0 yaml_2.3.12
## [28] parallel_4.6.1 tools_4.6.1 tzdb_0.5.0
## [31] vctrs_0.7.3 R6_2.6.1 lifecycle_1.0.5
## [34] bit_4.6.0 vroom_1.7.1 pkgconfig_2.0.3
## [37] pillar_1.11.1 bslib_0.12.0 gtable_0.3.6
## [40] glue_1.8.1 Rcpp_1.1.2 xfun_0.60
## [43] tidyselect_1.2.1 rstudioapi_0.19.0 knitr_1.52
## [46] farver_2.1.2 htmltools_0.5.9 rmarkdown_2.32
## [49] labeling_0.4.3 readr_2.2.0 compiler_4.6.1
## [52] S7_0.2.2 readxl_1.5.0 distributional_0.9.0