Use the given code below to answer the questions.

## Load package
library(tidyverse) # for cleaning, plotting, etc
library(tidyquant) # for financial analysis

## Import data
stocks <- tq_get("AAPL", get = "stock.prices", from = "2016-01-01")
stocks
## # A tibble: 1,033 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2016-01-04 103.  105.  102   105.  67649400     98.2
##  2 2016-01-05 106.  106.  102.  103.  55791000     95.8
##  3 2016-01-06 101.  102.   99.9 101.  68457400     93.9
##  4 2016-01-07  98.7 100.   96.4  96.4 81094400     89.9
##  5 2016-01-08  98.6  99.1  96.8  97.0 70798000     90.4
##  6 2016-01-11  99.0  99.1  97.3  98.5 49739400     91.9
##  7 2016-01-12 101.  101.   98.8 100.  49154200     93.2
##  8 2016-01-13 100.  101.   97.3  97.4 62439600     90.8
##  9 2016-01-14  98.0 100.   95.7  99.5 63170100     92.8
## 10 2016-01-15  96.2  97.7  95.4  97.1 79833900     90.6
## # … with 1,023 more rows
## Visualize
stocks %>%
  ggplot(aes(x = date, y = adjusted)) +
  geom_line()

Q1 Import Netflix stock prices, instead of Apple.

library(tidyverse) # for cleaning, plotting, etc
library(tidyquant) # for financial analysis

stocks <- tq_get("NFLX", get = "stock.prices", from = "2017-01-01")
stocks
## # A tibble: 781 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2017-01-03  125.  128.  124.  127.  9437900     127.
##  2 2017-01-04  127.  130.  127.  129.  7843600     129.
##  3 2017-01-05  129.  133.  129.  132. 10185500     132.
##  4 2017-01-06  132.  134.  130.  131. 10657900     131.
##  5 2017-01-09  131.  132.  130.  131.  5771800     131.
##  6 2017-01-10  131.  132.  129.  130.  5985800     130.
##  7 2017-01-11  131.  132.  129.  130.  5615100     130.
##  8 2017-01-12  131.  131.  128.  129.  5388900     129.
##  9 2017-01-13  131.  134.  131.  134. 10515000     134.
## 10 2017-01-17  135.  135.  132.  133. 12220200     133.
## # … with 771 more rows

Q2 How many shares of the stock were traded on January 13, 2017?

10515000 shares of the stock were traded on January 13, 2017.

Q3 Stock prices in this data would be a good example of numeric data. Character and logical are two other basic data types in R. List one example of character data and one example of logical data.

An example of logical data would be binary and an example would be true or false. Character data is when the data is a string of one or more characters. An example of character data would be “two” or “three”.

Q4 Plot the closing price in a line chart.

stocks %>%
  ggplot(aes(x = date, y = adjusted)) +
  geom_line()

For more information on the ggplot() function, refer to Ch2 Introduction to ggplot2 in one of our e-textbooks, Data Visualization with R.

Q5 From the chart you created in Q4, briefly describe how the Netflix stock has performed since the beginning of 2019.

The Netflix stock had decreased in 2019 slightly to below 300, but started to rise again by the end of 2019.

Q6 Import two stocks: Netflix and Amazon for the same time period.

library(tidyverse) # for cleaning, plotting, etc
library(tidyquant) # for financial analysis

## Import data
stocks <- tq_get("NFLX", "AMZN", get = "stock.prices", from = "2017-01-01")
stocks
## # A tibble: 781 x 7
##    date        open  high   low close   volume adjusted
##    <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 2017-01-03  125.  128.  124.  127.  9437900     127.
##  2 2017-01-04  127.  130.  127.  129.  7843600     129.
##  3 2017-01-05  129.  133.  129.  132. 10185500     132.
##  4 2017-01-06  132.  134.  130.  131. 10657900     131.
##  5 2017-01-09  131.  132.  130.  131.  5771800     131.
##  6 2017-01-10  131.  132.  129.  130.  5985800     130.
##  7 2017-01-11  131.  132.  129.  130.  5615100     130.
##  8 2017-01-12  131.  131.  128.  129.  5388900     129.
##  9 2017-01-13  131.  134.  131.  134. 10515000     134.
## 10 2017-01-17  135.  135.  132.  133. 12220200     133.
## # … with 771 more rows

Q7 Hide the messages and the results of the code, but display the code on the webpage.

Q8 Make an exception to the code chunk in Q6 by displaying both the code and its results.

Hint: Use echo and results in the chunk option. Note that this question only applies to the individual code chunk of Q6.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.