This report compares Google search interest and stock price performance for COUR (Coursera) and PSO (Pearson) over the past four years.
# Install packages (only needed once)
# install.packages("gtrendsR")
# install.packages("quantmod")
# install.packages("lubridate")
library(gtrendsR)
library(quantmod)
library(lubridate)
stock_trends <- gtrends(c("COUR", "PSO"),
gprop = "web",
geo = c("US"))
plot(stock_trends)
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## ℹ The deprecated feature was likely used in the gtrendsR package.
## Please report the issue at <https://github.com/PMassicotte/gtrendsR/issues>.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Download stock data
getSymbols('COUR', src = 'yahoo',
from = Sys.Date() - years(4),
to = Sys.Date())
## [1] "COUR"
getSymbols('PSO', src = 'yahoo',
from = Sys.Date() - years(4),
to = Sys.Date())
## [1] "PSO"
# Combine closing prices
stocks <- as.xts(data.frame(COUR = COUR$COUR.Close,
PSO = PSO$PSO.Close))
# Plot stock prices
plot(as.zoo(stocks),
screens = 1,
lty = c(1,3),
col = c("blue","red"),
xlab = "Date",
ylab = "Price")
legend("top", c("COUR","PSO"),
lty = c(1,3),
col = c("blue","red"),
cex = 0.7)