Import stock prices

stocks <- tq_get(c("CVX", "XOM"),
                 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 CVX    2016-01-04  89.5  90.1  87.6  88.8 11397300     65.7
##  2 CVX    2016-01-05  89.1  89.7  87.8  89.6  7883400     66.3
##  3 CVX    2016-01-06  87.4  87.8  85.2  86.1 14511400     63.6
##  4 CVX    2016-01-07  84.6  85.8  82.7  83.0 15368800     61.4
##  5 CVX    2016-01-08  83.4  83.8  81.2  82.1 11891600     60.7
##  6 CVX    2016-01-11  82.8  83.0  79.8  80.8 14366400     59.7
##  7 CVX    2016-01-12  82.2  82.4  79.7  82.2 13477500     60.7
##  8 CVX    2016-01-13  83.2  84.2  80.0  81.3 15550100     60.1
##  9 CVX    2016-01-14  81.9  86.2  80.9  85.5 16433400     63.2
## 10 CVX    2016-01-15  81.6  83.8  80.9  83.7 17870300     61.9
## # … with 494 more rows

Plot stock prices

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