library(fpp3)
?aus_production
?pelt
?gafa_stock
?vic_elec
library(fpp3)
autoplot(aus_production, Bricks)
autoplot(pelt, Lynx)
autoplot(gafa_stock, Close)
autoplot(vic_elec, Demand) + ggtitle("Quarterly electricity demand for Victoria, Australia") + xlab("Time") + ylab ("Demand in MWh")
gafa_stock %>%
group_by(Symbol) %>%
filter(Close == max(Close)) %>%
select(Symbol, Date)
## # A tsibble: 4 x 2 [!]
## # Key: Symbol [4]
## # Groups: Symbol [4]
## Symbol Date
## <chr> <date>
## 1 AAPL 2018-10-03
## 2 AMZN 2018-09-04
## 3 FB 2018-07-25
## 4 GOOG 2018-07-26
tute1 <- readr::read_csv("C:\\Users\\John Ledesma\\Downloads\\tute1.csv")
## Rows: 100 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): Sales, AdBudget, GDP
## date (1): Quarter
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(tute1)
mytimeseries <- tute1 |>
mutate(Quarter = yearquarter(Quarter)) |>
as_tsibble(index = Quarter)
mytimeseries |>
pivot_longer(-Quarter) |>
ggplot(aes(x = Quarter, y = value, colour = name)) +
geom_line() +
facet_grid(name ~ ., scales = "free_y")
library('USgas')
us_total_tsibble <- as_tsibble(us_total, key = state, index = year)
new_england_gas <- filter(us_total_tsibble, state %in% c("Maine", "Vermont", "New Hampshire", "Massachusetts", "Connecticut", "Rhode Island"))
autoplot(new_england_gas) + ggtitle("New England Gas Consumption") + xlab("Year") + ylab( "Natural Gas")
## Plot variable not specified, automatically selected `.vars = y`
library(readxl)
tourism_xl <- read_excel("C:\\Users\\John Ledesma\\Downloads\\tourism.xlsx")
tourism_xl <- tourism_xl %>%
mutate(Quarter = yearquarter(Quarter))
tourism_tsibble <- tourism_xl %>%
as_tsibble(key = c(Region,State,Purpose), index = Quarter)
tourism_R_and_P <- tourism_xl %>%
group_by(Region, Purpose) %>%
summarise(Total_trips = sum(Trips,na.rm=TRUE)) %>%
arrange(desc(Total_trips))
## `summarise()` has grouped output by 'Region'. You can override using the
## `.groups` argument.
head(tourism_R_and_P)
## # A tibble: 6 × 3
## # Groups: Region [4]
## Region Purpose Total_trips
## <chr> <chr> <dbl>
## 1 Sydney Visiting 59782.
## 2 Melbourne Visiting 49512.
## 3 Sydney Business 48164.
## 4 North Coast NSW Holiday 47032.
## 5 Sydney Holiday 44026.
## 6 Gold Coast Holiday 42267.
Sydney/Visiting is the leading Region/Purpose
tourism_group <- tourism_xl %>%
group_by(State) %>%
summarise(Total_Trips = sum(Trips, na.rm = TRUE)) %>%
arrange(desc(Total_Trips))
tourism_group
## # A tibble: 8 × 2
## State Total_Trips
## <chr> <dbl>
## 1 New South Wales 557367.
## 2 Victoria 390463.
## 3 Queensland 386643.
## 4 Western Australia 147820.
## 5 South Australia 118151.
## 6 Tasmania 54137.
## 7 ACT 41007.
## 8 Northern Territory 28614.
2.8) Use the following graphics functions: autoplot(), gg_season(), gg_subseries(), gg_lag(), ACF() and explore features from the following time series: “Total Private” Employed from us_employment, Bricks from aus_production, Hare from pelt, “H02” Cost from PBS, and Barrels from us_gasoline. Can you spot any seasonality, cyclicity and trend? What do you learn about the series? What can you say about the seasonal patterns? Can you identify any unusual years?
US_Total_Private <- us_employment %>% filter(Title=="Total Private")
Bricks <- aus_production %>% select(Quarter, Bricks)
Hare <- pelt %>% select(Year, Hare)
H02 <- PBS %>% filter(ATC2 == 'H02')
autoplot(US_Total_Private)
## Plot variable not specified, automatically selected `.vars = Employed`
autoplot(Bricks)
## Plot variable not specified, automatically selected `.vars = Bricks`
autoplot(Hare)
## Plot variable not specified, automatically selected `.vars = Hare`
autoplot(H02)
## Plot variable not specified, automatically selected `.vars = Scripts`
gg_season(US_Total_Private)
## Plot variable not specified, automatically selected `y = Employed`
gg_season(Bricks)
## Plot variable not specified, automatically selected `y = Bricks`
gg_season(H02)
## Plot variable not specified, automatically selected `y = Scripts`
gg_subseries(US_Total_Private)
## Plot variable not specified, automatically selected `y = Employed`
gg_subseries(Bricks)
## Plot variable not specified, automatically selected `y = Bricks`
gg_subseries(Hare)
## Plot variable not specified, automatically selected `y = Hare`
gg_subseries(H02)
## Plot variable not specified, automatically selected `y = Scripts`
gg_lag(US_Total_Private, geom = 'point')
## Plot variable not specified, automatically selected `y = Employed`
gg_lag(Bricks, geom = 'point')
## Plot variable not specified, automatically selected `y = Bricks`
gg_lag(Hare, geom = 'point')
## Plot variable not specified, automatically selected `y = Hare`
Based on the graphs of the data, I can make a few observations. For US employment, we can see there is a general upward trend with slight dips in February and peaks in June and July. For Bricks there was a large dip in bricks in quarter 2 of 1980 and Quarter 3 of each year seems to produce more For Hare,