We will be plotting the Google and Amazon Stock prices since Jan 1 2021
suppressMessages(library(dplyr))
suppressMessages(library(htmltools))
## Warning: package 'htmltools' was built under R version 4.0.5
suppressMessages(library(tidyquant))
## Warning: package 'tidyquant' was built under R version 4.0.5
## Warning: package 'PerformanceAnalytics' was built under R version 4.0.5
suppressMessages(library(plotly))
## Warning: package 'plotly' was built under R version 4.0.5
We can take the data directly using the tidyquant library
data <- tq_get(c("AMZN", "GOOG"), from = "2021-01-01")
p <-
data %>%
dplyr::group_by(symbol) %>%
dplyr::mutate(adjusted = adjusted / adjusted[1L]) %>%
plotly::plot_ly(x = ~date, y = ~adjusted, color = ~symbol,
type = "scatter", mode = "lines") %>%
rangeslider(borderwidth = 2)
options(warn = - 1)
p
options(warn = 0)