Key Reference: RMarkdown - The Definitive Guide
PDF Printing Setup: tinytex
# PDF Knitting Setup: https://yihui.name/tinytex/
# install.packages("tintex")
# tinytex::install_tinytex()# Import stock prices
stocks <- tq_get(c("AMZN", "MSFT"),
get = "stock.prices",
from = "2016-01-01",
to = "2023-01-01")
stocks## # A tibble: 3,524 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AMZN 2016-01-04 32.8 32.9 31.4 31.8 186290000 31.8
## 2 AMZN 2016-01-05 32.3 32.3 31.4 31.7 116452000 31.7
## 3 AMZN 2016-01-06 31.1 32.0 31.0 31.6 106584000 31.6
## 4 AMZN 2016-01-07 31.1 31.5 30.3 30.4 141498000 30.4
## 5 AMZN 2016-01-08 31.0 31.2 30.3 30.4 110258000 30.4
## 6 AMZN 2016-01-11 30.6 31.0 29.9 30.9 97832000 30.9
## 7 AMZN 2016-01-12 31.3 31.3 30.6 30.9 94482000 30.9
## 8 AMZN 2016-01-13 31.0 31.0 29.0 29.1 153104000 29.1
## 9 AMZN 2016-01-14 29.0 30.1 28.5 29.6 144760000 29.6
## 10 AMZN 2016-01-15 28.6 29.2 28.3 28.5 155690000 28.5
## # … with 3,514 more rows
Plotting works as expected. Try changing:
out.height, out.width and KnittingStatic plots:
g <- ggplot(data = stocks) +
geom_point(mapping = aes(x = volume, y = adjusted, color = symbol))
gRevenue by Category
Interactive plots:
ggplotly().ggplotly(g)Static Tables:
knitr package - knitr::kable() - Simple to
use, great with PDFstocks %>% head() %>% knitr::kable()| symbol | date | open | high | low | close | volume | adjusted |
|---|---|---|---|---|---|---|---|
| AMZN | 2016-01-04 | 32.8145 | 32.8860 | 31.3755 | 31.8495 | 186290000 | 31.8495 |
| AMZN | 2016-01-05 | 32.3430 | 32.3455 | 31.3825 | 31.6895 | 116452000 | 31.6895 |
| AMZN | 2016-01-06 | 31.1000 | 31.9895 | 31.0155 | 31.6325 | 106584000 | 31.6325 |
| AMZN | 2016-01-07 | 31.0900 | 31.5000 | 30.2605 | 30.3970 | 141498000 | 30.3970 |
| AMZN | 2016-01-08 | 30.9830 | 31.2070 | 30.3000 | 30.3525 | 110258000 | 30.3525 |
| AMZN | 2016-01-11 | 30.6240 | 30.9925 | 29.9285 | 30.8870 | 97832000 | 30.8870 |
Dynamic Tables:
stocks## # A tibble: 3,524 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AMZN 2016-01-04 32.8 32.9 31.4 31.8 186290000 31.8
## 2 AMZN 2016-01-05 32.3 32.3 31.4 31.7 116452000 31.7
## 3 AMZN 2016-01-06 31.1 32.0 31.0 31.6 106584000 31.6
## 4 AMZN 2016-01-07 31.1 31.5 30.3 30.4 141498000 30.4
## 5 AMZN 2016-01-08 31.0 31.2 30.3 30.4 110258000 30.4
## 6 AMZN 2016-01-11 30.6 31.0 29.9 30.9 97832000 30.9
## 7 AMZN 2016-01-12 31.3 31.3 30.6 30.9 94482000 30.9
## 8 AMZN 2016-01-13 31.0 31.0 29.0 29.1 153104000 29.1
## 9 AMZN 2016-01-14 29.0 30.1 28.5 29.6 144760000 29.6
## 10 AMZN 2016-01-15 28.6 29.2 28.3 28.5 155690000 28.5
## # … with 3,514 more rows