Explore the following four time series: Bricks from aus_production, Lynx from pelt, Close from gafa_stock, Demand from vic_elec. Use ? (or help()) to find out about the data in each series.
# A tsibble: 4 x 3 [!]
# Key: Symbol [4]
# Groups: 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.
2.3
Download the file tute1.csv from the book website, open it in Excel (or some other spreadsheet application), and review its contents. You should find four columns of information. Columns B through D each contain a quarterly series, labelled Sales, AdBudget and GDP. Sales contains the quarterly sales for a small company over the period 1981-2005. AdBudget is the advertising budget and GDP is the gross domestic product. All series have been adjusted for inflation. You can read and view data with the code below, but check out what happens if you don’t include facet_grid()
The USgas package contains data on the demand for natural gas in the US. Install the USgas package. Create a tsibble from us_total with year as the index and state as the key. Plot the annual natural gas consumption by state for the New England area (comprising the states of Maine, Vermont, New Hampshire, Massachusetts, Connecticut and Rhode Island).
library(ggplot2)library(USgas)head(usgas)
date process state state_abb y
1 1973-01-01 Commercial Consumption U.S. U.S. 392315
2 1973-01-01 Residential Consumption U.S. U.S. 843900
3 1973-02-01 Commercial Consumption U.S. U.S. 394281
4 1973-02-01 Residential Consumption U.S. U.S. 747331
5 1973-03-01 Commercial Consumption U.S. U.S. 310799
6 1973-03-01 Residential Consumption U.S. U.S. 648504
USgas_ts <-as_tsibble(us_total, index = year, key = state)NES<-c("Maine", "Vermont", "New Hampshire", "Massachusetts", "Connecticut", "Rhode Island")NES_gas <- USgas_ts %>%filter(state %in% NES)ggplot(NES_gas, aes(x = year, y = y, color = state)) +geom_line() +labs(title ="New England Annual Natural Gas Consumption ",x ="Year",y ="Consumption") +theme_minimal()
2.5
Download tourism.xlsx from the book website and read it into R using read_excel(), and create a tsibble which is identical to the tourism tsibble from the tsibble package.
# A tsibble: 24,320 x 5 [1Q]
# Key: Region, State, Purpose [304]
Quarter Region State Purpose Trips
<qtr> <chr> <chr> <chr> <dbl>
1 1998 Q1 Adelaide South Australia Business 135.
2 1998 Q2 Adelaide South Australia Business 110.
3 1998 Q3 Adelaide South Australia Business 166.
4 1998 Q4 Adelaide South Australia Business 127.
5 1999 Q1 Adelaide South Australia Business 137.
6 1999 Q2 Adelaide South Australia Business 200.
7 1999 Q3 Adelaide South Australia Business 169.
8 1999 Q4 Adelaide South Australia Business 134.
9 2000 Q1 Adelaide South Australia Business 154.
10 2000 Q2 Adelaide South Australia Business 169.
# ℹ 24,310 more rows
Use the following graphics functions: autoplot(), gg_season(), gg_subseries(), gg_lag(), ACF() and explore features from the following time series: Employed from us_employment, Bricks from aus_production, Hare from pelt, Cost from PBS, and Barrels from us_gasoline.