# Load packages
library(tidyquant)
library(tidyverse)

# Import stock prices
stock_prices <- tq_get(c("AAPL", "MSFT"), get  = "stock.prices", from = "2020-01-01")

stock_prices
## # A tibble: 70 x 8
##    symbol date        open  high   low close   volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 AAPL   2020-01-02  296.  301.  295.  300. 33870100     300.
##  2 AAPL   2020-01-03  297.  301.  296.  297. 36580700     297.
##  3 AAPL   2020-01-06  294.  300.  293.  300. 29596800     299.
##  4 AAPL   2020-01-07  300.  301.  297.  298. 27218000     298.
##  5 AAPL   2020-01-08  297.  304.  297.  303. 33019800     302.
##  6 AAPL   2020-01-09  307.  310.  306.  310. 42527100     309.
##  7 AAPL   2020-01-10  311.  313.  308.  310. 35161200     310.
##  8 AAPL   2020-01-13  312.  317.  311.  317. 30383000     316.
##  9 AAPL   2020-01-14  317.  318.  312.  313. 40488600     312.
## 10 AAPL   2020-01-15  312.  316.  310.  311. 30480900     311.
## # … with 60 more rows

Q1 Select Apple stock prices and save it under plotdata.

library(dplyr)
plotdata <- filter(stock_prices, 
                   symbol == "AAPL")
plotdata
## # A tibble: 35 x 8
##    symbol date        open  high   low close   volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>
##  1 AAPL   2020-01-02  296.  301.  295.  300. 33870100     300.
##  2 AAPL   2020-01-03  297.  301.  296.  297. 36580700     297.
##  3 AAPL   2020-01-06  294.  300.  293.  300. 29596800     299.
##  4 AAPL   2020-01-07  300.  301.  297.  298. 27218000     298.
##  5 AAPL   2020-01-08  297.  304.  297.  303. 33019800     302.
##  6 AAPL   2020-01-09  307.  310.  306.  310. 42527100     309.
##  7 AAPL   2020-01-10  311.  313.  308.  310. 35161200     310.
##  8 AAPL   2020-01-13  312.  317.  311.  317. 30383000     316.
##  9 AAPL   2020-01-14  317.  318.  312.  313. 40488600     312.
## 10 AAPL   2020-01-15  312.  316.  310.  311. 30480900     311.
## # … with 25 more rows

Q2 Create a simple line plot with date on the x-axis and closing price on the y-axis.

ggplot(plotdata, 
       aes(x = date, 
           y = close)) +
  geom_line() 

Q3 Add the color (cornflowerblue) to the line plot.

ggplot(plotdata, 
       aes(x = date, 
           y = close)) +
  geom_line(color = "cornflowerblue")

Q4 Make the line thicker in the line plot.

 ggplot(plotdata, 
       aes(x = date, 
           y = close)) +
  geom_line(size = 1.5, color = "cornflowerblue")

Q5 Label the y-axis as “Closing Price”.

ggplot(plotdata, 
       aes(x = date, 
           y = close)) +
  geom_line(size = 1.5, color = "cornflowerblue") +
  labs(y = "Closing Price")

Q6 Remove the label of the x-axis.

ggplot(plotdata, 
       aes(x = date, 
           y = close)) +
  geom_line(size = 1.5, color = "cornflowerblue") +
  labs(y = "Closing Price",
       x = " ")

Q7 Create the line plot for both Apple and Microsoft.

library(ggplot2)
ggplot(stock_prices, 
       aes(x = date, y = close, 
           group = symbol, color = symbol)) +
  geom_line() 

Q8 Hide the messages, but display the code and its results on the webpage.

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

Q10 Use the correct slug.