library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
getSymbols('AMZN', src = 'yahoo', 
           from = Sys.Date() - years(4), to = Sys.Date())
## [1] "AMZN"
getSymbols('TSLA', src = 'yahoo', 
           from = Sys.Date() - years(4), to = Sys.Date())
## [1] "TSLA"
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)