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.



Contents:

Loading required R packages

# Load required R packages
library(dplyr)
library(highcharter) 
# 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.

library(quantmod)
x <- getFX("USD/JPY", auto.assign = FALSE)
df <- as.data.frame(x)
head(df)
##            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)
hc

Visualize quantmod symbols data from different sources

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

Create highstock chart from a data frame

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



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