In this exercise you will learn to plot data using the ggplot2 package. To answer the questions below, use Chapter 4.3 Categorical vs. Quantitative Data Visualization with R.
# Load packages
library(tidyquant)
library(tidyverse)
# Import stock prices
stock_prices <- tq_get(c("AAPL", "MSFT"), get = "stock.prices", from = "2020-01-01")
Hint: See the code in 4.2.2 Line plot.
library(dplyr)
plotdata <- filter(stock_prices,
symbol == "AAPL")
Hint: See the code in 4.2.2 Line plot.
ggplot(plotdata,
aes(x = date,
y = close)) +
geom_line()
Hint: See the code in 4.2.2 Line plot.
ggplot(plotdata,
aes(x = date,
y = close)) +
geom_line(color= "cornflowerblue")
Hint: See the code in 4.2.2 Line plot.
ggplot(plotdata,
aes(x = date,
y = close)) +
geom_line(size= 2, color= "cornflowerblue")
Hint: See the code in 4.2.2 Line plot.
ggplot(plotdata,
aes(x = date,
y = close)) +
geom_line(size= 2, color= "cornflowerblue") +
labs(y = "Closing Price")
Hint: See the code in 4.2.2 Line plot.
ggplot(plotdata,
aes(x = date,
y = close)) +
geom_line(size= 2, color= "cornflowerblue") +
labs(y = "Closing Price",
x = "")
Hint: Google search something like “ggplot2 two lines”.
ggplot(stock_prices,
aes(x = date,
y = close,
col = symbol)) +
geom_line()
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.