Charting one ETF H IGH CH ARTER F OR F IN AN CE IN R Jonathan K. Regenstein, Jr. Director of Financial Services, RStudio, Inc.
Five ETF prices in one xts object etf_prices_xts SPY EFA IJS EEM AGG 2012-12-31 128.3092 49.16410 75.06590 39.89233 98.19626 2013-01-02 131.5977 49.92501 77.12553 40.67489 98.08131 2013-01-03 131.3004 49.44080 77.02349 40.38705 97.83374 2013-01-04 131.8771 49.69155 77.62656 40.46800 97.93983 2013-01-07 131.5166 49.47539 77.17194 40.16218 97.88681 2013-01-08 131.1382 49.19869 76.87505 39.80238 97.97523 2013-01-09 131.4716 49.44944 77.09772 39.97328 97.90449 2013-01-10 132.5168 50.08064 77.19049 40.32409 97.89565 2013-01-11 132.5077 50.18440 77.13483 40.00026 97.99291 2013-01-14 132.4177 50.24492 77.11628 40.17117 98.08131 HIGHCHARTER FOR FINANCE IN R
A line chart of SPY etf_prices_xts$SPY SPY 2012-12-31 128.3092 2013-01-02 131.5977 2013-01-03 131.3004 2013-01-04 131.8771 2013-01-07 131.5166 2013-01-08 131.1382 2013-01-09 131.4716 2013-01-10 132.5168 2013-01-11 132.5077 2013-01-14 132.4177 HIGHCHARTER FOR FINANCE IN R
Start with a blank chart highchart(type = "stock") HIGHCHARTER FOR FINANCE IN R
Add data highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY) HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Chart the price of EEM highchart(type = "stock") %>% hc_add_series(etf_prices_xts$EEM, color = "green") HIGHCHARTER FOR FINANCE IN R
Let's chart some ETF prices! H IGH CH ARTER F OR F IN AN CE IN R
Chart the price of many stocks from xts H IGH CH ARTER F OR F IN AN CE IN R Jonathan K. Regenstein, Jr. Director of Financial Services, RStudio, Inc.
Multiple ETFs for charting etf_prices_xts SPY EFA IJS EEM AGG 2012-12-31 128.3092 49.16410 75.06590 39.89233 98.19626 2013-01-02 131.5977 49.92501 77.12553 40.67489 98.08131 2013-01-03 131.3004 49.44080 77.02349 40.38705 97.83374 2013-01-04 131.8771 49.69155 77.62656 40.46800 97.93983 2013-01-07 131.5166 49.47539 77.17194 40.16218 97.88681 2013-01-08 131.1382 49.19869 76.87505 39.80238 97.97523 2013-01-09 131.4716 49.44944 77.09772 39.97328 97.90449 2013-01-10 132.5168 50.08064 77.19049 40.32409 97.89565 2013-01-11 132.5077 50.18440 77.13483 40.00026 97.99291 2013-01-14 132.4177 50.24492 77.11628 40.17117 98.08131 HIGHCHARTER FOR FINANCE IN R
Add another series highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY) %>% hc_add_series(etf_prices_xts$IJS) HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Color each series highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue") %>% hc_add_series(etf_prices_xts$IJS, color = "red") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Naming the series highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_add_series(etf_prices_xts$IJS, color = "red", name = "IJS") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Two price histories on a customized chart HIGHCHARTER FOR FINANCE IN R
Three ETFs highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_add_series(etf_prices_xts$IJS, color = "red", name = "IJS") %>% hc_add_series(etf_prices_xts$EEM, color = "green", name = "EEM") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Let's practice charting several price histories! H IGH CH ARTER F OR F IN AN CE IN R
Title, subtitle and axes (not of evil)! H IGH CH ARTER F OR F IN AN CE IN R Jonathan K. Regenstein, Jr. Director of Financial Services, RStudio, Inc.
Adding a title highchart(type = "stock") %>% hc_title(text = "5 ETFs Price History") HIGHCHARTER FOR FINANCE IN R
Adding a subtitle highchart(type = "stock") %>% hc_title(text = "5 ETFs Price History") %>% hc_subtitle(text = "daily prices") HIGHCHARTER FOR FINANCE IN R
Title, subtitle, and data highchart(type = "stock") %>% hc_title(text = "5 ETFs Price History") %>% hc_subtitle(text = "daily prices") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_add_series(etf_prices_xts$IJS, color = "red", name = "IJS") %>% hc_add_series(etf_prices_xts$EEM, color = "green", name = "EEM") %>% hc_add_series(etf_prices_xts$EFA, color = "purple", name = "EFA") %>% hc_add_series(etf_prices_xts$AGG, color = "orange", name = "AGG") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Customizing the y-axis highchart(type = "stock") %>% hc_title(text = "5 ETFs Price History") %>% hc_subtitle(text = "daily prices") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_add_series(etf_prices_xts$IJS, color = "red", name = "IJS") %>% hc_add_series(etf_prices_xts$EEM, color = "green", name = "EEM") %>% hc_add_series(etf_prices_xts$EFA, color = "purple", name = "EFA") %>% hc_add_series(etf_prices_xts$AGG, color = "orange", name = "AGG") hc_yAxis(title = list(text = "Prices (USD)"), labels = list(format = "${value}"), opposite = FALSE) HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Let's practice the title, subtitle and y- axis H IGH CH ARTER F OR F IN AN CE IN R
Tooltips and legends H IGH CH ARTER F OR F IN AN CE IN R Jonathan K. Regenstein, Jr. Director of Financial Services, RStudio, Inc.
HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Customizing the tooltip highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_tooltip(pointFormat = "text in the tooltip") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Dynamic tooltip highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_tooltip(pointFormat = "${point.y}") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Rounding the tooltip highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_tooltip(pointFormat = "${point.y: .2f}") HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Dynamic tooltip names highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_tooltip(pointFormat = "{point.series.name}: ${point.y: .2f}) HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Adding a legend highchart(type = "stock") %>% hc_add_series(etf_prices_xts$SPY, color = "blue", name = "SPY") %>% hc_add_series(etf_prices_xts$IJS, color = "red", name = "IJS") %>% hc_add_series(etf_prices_xts$EEM, color = "green", name = "EEM") %>% hc_add_series(etf_prices_xts$EFA, color = "purple", name = "EFA") %>% hc_add_series(etf_prices_xts$AGG, color = "orange", name = "XXX") %>% hc_yAxis(title = list(text = "Prices (USD)"), labels = list(format = "${value}"), opposite = FALSE) %>% hc_tooltip(pointFormat = "{point.series.name}: ${point.y: .2f}") %>% hc_legend(enabled = TRUE) HIGHCHARTER FOR FINANCE IN R
HIGHCHARTER FOR FINANCE IN R
Let's go customize some tooltips and add some legends! H IGH CH ARTER F OR F IN AN CE IN R
Recommend
More recommend