I am trying to use the quant mod library to get stocks' values and using gtrends library compare them, however, I haven't reached the second part of my analysis because I am stuck trying to understand and fix my problem. The code is as follows:
#Loading the libraries that I will start using to analyze the data
library(quantmod)
library(dplyr)
library(tidyverse)
library(tidyr)
#Getting stock tickers for: Square, Wells Fargo, JPMorgan Chase, Visa, and Mastercard
getSymbols(c("SQ", "JPM", "WFC", "V", "MA"))
#Merging the stock data into one data frame
stocks <- data.frame( "Square" = SQ$SQ.Close, "JPMorgan" = JPM$JPM.Close, "WellsFargo" = WFC$WFC.Close, "Visa" = V$V.Close, "Mastercard" = MA$MA.Close, "Date" = as.Date(row.names(as.data.frame(SQ))))
plotting <- stocks %>% gather(key = "stock", value = "value", -Date)
plotting %>% ggplot() + geom_line(aes(x = Date, y = value, color = stock)) +
scale_color_discrete(name = "Company", labels = c("JPMorgan", "Mastercard", "Square", "Visa", "Wells Fargo")) +
labs(title = "Stock Prices of Financial Companies", y = "Stock Price")