installed.packages("tidyquant")
##      Package LibPath Version Priority Depends Imports LinkingTo Suggests
##      Enhances License License_is_FOSS License_restricts_use OS_type Archs
##      MD5sum NeedsCompilation Built

Import stock prices

stocks <- tq_get(c("AAPL", "MSFT"),
                 get = "stock.prices",
                 from = "2016-01-01",
                 to = "2017-01-01")
stocks
## # A tibble: 504 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 AAPL   2016-01-04  25.7  26.3  25.5  26.3 270597600     23.8
##  2 AAPL   2016-01-05  26.4  26.5  25.6  25.7 223164000     23.2
##  3 AAPL   2016-01-06  25.1  25.6  25.0  25.2 273829600     22.7
##  4 AAPL   2016-01-07  24.7  25.0  24.1  24.1 324377600     21.8
##  5 AAPL   2016-01-08  24.6  24.8  24.2  24.2 283192000     21.9
##  6 AAPL   2016-01-11  24.7  24.8  24.3  24.6 198957600     22.2
##  7 AAPL   2016-01-12  25.1  25.2  24.7  25.0 196616800     22.6
##  8 AAPL   2016-01-13  25.1  25.3  24.3  24.3 249758400     22.0
##  9 AAPL   2016-01-14  24.5  25.1  23.9  24.9 252680400     22.5
## 10 AAPL   2016-01-15  24.0  24.4  23.8  24.3 319335600     21.9
## # ℹ 494 more rows

Plot stock prices

stocks %>%
    
    ggplot(aes(x = date, y = adjusted, color = symbol)) +
    geom_line()