Highcharter R Package Essentials for Easy Interactive Graphs

Highchart Interactive Highstock Plot in R

This article describes how to create a highstock chart in R using the highcharter R package.


Loading required R packages

# Load required R packages
# Set highcharter options
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))

Data preparation

Download exchange rates using the quantmod R package. The function getFX() is used. It returns an object of class xts which can be directly plotted using the highcharter R package.

x <- getFX("USD/JPY", auto.assign = FALSE)
df <- as.data.frame(x)
##            USD.JPY
## 2019-10-31     108
## 2019-11-01     108
## 2019-11-02     108
## 2019-11-03     108
## 2019-11-04     108
## 2019-11-05     109

Visualize quantmod xts data

hc <- hchart(x)

Visualize quantmod symbols data from different sources

# `xts ohlc` objects
y <- getSymbols("SPY", auto.assign = FALSE)
hc <- hchart(y)

Create highstock chart from a data frame

hc <- highchart(type = "stock") %>% 
   hc_add_series(df$USD.JPY, type = "line")

Version: Français

Highchart Interactive World Map in R (Prev Lesson)
(Next Lesson) Highchart Interactive Pie Chart and Alternatives in R
Back to Highcharter R Package Essentials for Easy Interactive Graphs

No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments