autoplot(gafa_stock, Open) +
ggtitle("Historical stock prices", subtitle = "2014-2018")
autoplot(vic_elec, Demand) +
ggtitle("Hald-hourly Electricity Demand", subtitle = "Victoria, Australia")
autoplot(pelt, Hare) +
ggtitle("The timeline for pel/Hare series", subtitle = "1945-1935")
gafa_stock : The time interval is 1 day PBS : It has not time interval vic_elec : The time interval is 30 minute / Half hour pelt : The time interval is 1 year
view(gafa_stock)
sum(is.na(gafa_stock))
## [1] 0
gafa_stock_close <- gafa_stock %>%
dplyr::select(Symbol,Date,Close) %>%
group_by(Symbol)%>%
filter(Close == max(Close)) %>%
arrange(desc(Close))
gafa_stock_close
## # A tsibble: 4 x 3 [!]
## # Key: Symbol [4]
## # Groups: Symbol [4]
## Symbol Date Close
## <chr> <date> <dbl>
## 1 AMZN 2018-09-04 2040.
## 2 GOOG 2018-07-26 1268.
## 3 AAPL 2018-10-03 232.
## 4 FB 2018-07-25 218.
tute1 <- readr::read_csv("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)
sum(is.na(tute1))
## [1] 0
mytimeseries <- tute1 %>%
mutate(Quarter = yearmonth(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") +
ggtitle("Facet grid")
mytimeseries %>%
pivot_longer(-Quarter) %>%
ggplot(aes(x = Quarter, y = value, colour = name)) +
geom_line() +
ggtitle("No facet grid")
view(us_total)
glimpse(us_total)
## Rows: 1,266
## Columns: 3
## $ year <int> 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007…
## $ state <chr> "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama"…
## $ y <int> 324158, 329134, 337270, 353614, 332693, 379343, 350345, 382367, …
us_total1 <- us_total %>%
as_tibble(index = year, key = state)%>%
filter(state == 'Connecticut' | state == 'Maine' | state == 'Massachusetts' | state == 'New Hampshire' | state == 'Rhode Island' | state == 'Vermont')#%>%
head(us_total1)
## # A tibble: 6 × 3
## year state y
## <int> <chr> <int>
## 1 1997 Connecticut 144708
## 2 1998 Connecticut 131497
## 3 1999 Connecticut 152237
## 4 2000 Connecticut 159712
## 5 2001 Connecticut 146278
## 6 2002 Connecticut 177587
ggplot(data= us_total1, aes(x = year, y = y, col = state)) +
geom_line() +
facet_grid(state ~ ., scales = "free_y") +
labs(title='Annual Natural Gas Consumption of New England Region')
tourism <- readxl::read_excel("tourism.xlsx")
View(tourism)
sum(is.na(tourism))
## [1] 0
tourism$Quarter <- yearquarter(as.Date(tourism$Quarter))
glimpse(tourism)
## Rows: 24,320
## Columns: 5
## $ Quarter <qtr> 1998 Q1, 1998 Q2, 1998 Q3, 1998 Q4, 1999 Q1, 1999 Q2, 1999 Q3,…
## $ Region <chr> "Adelaide", "Adelaide", "Adelaide", "Adelaide", "Adelaide", "A…
## $ State <chr> "South Australia", "South Australia", "South Australia", "Sout…
## $ Purpose <chr> "Business", "Business", "Business", "Business", "Business", "B…
## $ Trips <dbl> 135.0777, 109.9873, 166.0347, 127.1605, 137.4485, 199.9126, 16…
tourism1 <- tourism %>%
as_tsibble( index = Quarter, key = c(Region, State, Purpose))
tourism %>%
group_by(Region, Purpose) %>%
mutate(Avg_Trips = mean(Trips)) %>%
ungroup() %>%
filter(Avg_Trips == max(Avg_Trips)) %>%
distinct(Region, Purpose)
## # A tibble: 1 × 2
## Region Purpose
## <chr> <chr>
## 1 Sydney Visiting
tourism %>%
group_by(Quarter, State) %>%
mutate(Quarter = yearquarter(Quarter),
Total_Trips = sum(Trips)) %>%
select(Quarter, State, Total_Trips) %>%
distinct() %>%
as_tsibble(index = Quarter,
key = State)
## # A tsibble: 640 x 3 [1Q]
## # Key: State [8]
## # Groups: State @ Quarter [640]
## Quarter State Total_Trips
## <qtr> <chr> <dbl>
## 1 1998 Q1 ACT 551.
## 2 1998 Q2 ACT 416.
## 3 1998 Q3 ACT 436.
## 4 1998 Q4 ACT 450.
## 5 1999 Q1 ACT 379.
## 6 1999 Q2 ACT 558.
## 7 1999 Q3 ACT 449.
## 8 1999 Q4 ACT 595.
## 9 2000 Q1 ACT 600.
## 10 2000 Q2 ACT 557.
## # … with 630 more rows
set.seed(1975)
myseries <- aus_retail %>%
filter(`Series ID` == sample(aus_retail$`Series ID`,1))
autoplot(myseries)
## Plot variable not specified, automatically selected `.vars = Turnover`
gg_season(myseries)
## Plot variable not specified, automatically selected `y = Turnover`
gg_subseries(myseries)
## Plot variable not specified, automatically selected `y = Turnover`
gg_lag(myseries)
## Plot variable not specified, automatically selected `y = Turnover`
myseries %>%
ACF(Turnover)%>%
autoplot()