This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
install.packages(“gtrendsR”)
library(gtrendsR) midterm <- gtrends(c(“blue wave”, “red wave”), gprop = “web”, geo = c(“US”)) plot(midterm)
library(gtrendsR) stock_trends <- gtrends(c(“AMAZON”, “TESLA”), gprop = “web”, geo = c(“US”)) plot(stock_trends)
install.packages(“quantmod”)
install.packages(“lubridate”)
library(quantmod) library(lubridate) getSymbols(‘AMZN’, src = ‘yahoo’, from = Sys.Date() - years(4), to = Sys.Date())
getSymbols(‘TSLA’, src = ‘yahoo’, from = Sys.Date() - years(4), to = Sys.Date())
stocks <- as.xts(data.frame(AMZN = AMZN\("AMZN.Close", TSLA = TSLA\)“TSLA.Close”))
plot(as.zoo(stocks),screens = 1,lty = c(1,3), col = c(“red”,“blue”) ,xlab = “date”,ylab = “Price”) legend(“top”,c(“AMZN”,“TSLA”), lty = c(1,3),col = c(“red”,“blue”),cex = 0.5)