library(tidyverse)
library(plotly)
library(data.table)
aapl<- fread("data/AAPL.csv", select = c("Date", "Price"))
amzn <- fread("data/AMZN.csv", select = c("Date", "Price"))
tsla <- fread("data/TSLA.csv", select = c("Date", "Price"))
meta <- fread("data/META.csv", select = c("Date", "Price"))
gld <- fread("data/GLD.csv", select = c("Date", "Price"))
# Convert to Date yyyymmdd format
aapl$Date <- ymd(aapl$Date)
amzn$Date <- ymd(amzn$Date)
tsla$Date <- ymd(tsla$Date)
meta$Date <- ymd(meta$Date)
gld$Date <- ymd(gld$Date)
#Initialize plot_ly
aapl <- plot_ly(aapl, name = "Apple", x = ~Date, y = ~Price, type = "scatter", mode = "lines")
#Add markers from amzn
amzn <- plot_ly(amzn, name="Amazon", x = ~Date, y = ~Price, type = "scatter", mode = "lines + markers")
#Add markers from tsla
tsla <- plot_ly(tsla, name="Tesla", x = ~Date, y = ~Price, type = "scatter", mode = "lines + markers")
#Add markers from meta
meta <- plot_ly(meta, name="Meta", x = ~Date, y = ~Price, type = "scatter", mode = "lines + markers")
#Add markers from gld
gld <- plot_ly(gld, name="Gold", x = ~Date, y = ~Price, type = "scatter", mode = "lines + markers")
usStocks <- subplot(aapl, amzn, tsla, meta, gld,nrows = 5, shareX = TRUE, shareY = TRUE) %>% layout(title = "Stocks Prices - US$", xaxis = list("Date", nticks = 7), yaxis = list("Price"))
# Show graph
usStocks