Summary

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

Finding the Data

We can take the data directly using the tidyquant library

Loading and preprocessing the data

data <- tq_get(c("AMZN", "GOOG"), from = "2021-01-01")

Creating the Plot using plot_ly

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)

Plotting the two stock prices

options(warn = - 1)
p
options(warn = 0)