highcharter
packageThe package is free for non-commercial use but requires a license in corporate and government fields.
We can plot a variety of charts and maps that might not be available with plotly
and rbokeh
. More specifically: treemaps, better treatment of time series and stock charts (the related packages and topics such as autocovariance and autocorrelation), survival functions, sparkline charts. The package comes with over 500 themes (The Economist, Financial Times, Google, etc.). We can have motion charts like plotly
, but also drag points like JavaScript libraries.
Consult the demo site.
With the mtcars
dataset.
library(highcharter)
hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class))
With the AirPassengers
dataset.
library(forecast)
<- forecast(auto.arima(AirPassengers), level = 95)
airforecast
library(highcharter)
hchart(airforecast)
Average temperatures in New York City.
library(highcharter)
data(citytemp)
<- highchart() %>%
hc hc_xAxis(categories = citytemp$month) %>%
hc_add_series(name = "New York", data = citytemp$new_york) %>%
hc_xAxis(title = list(text = "Month"),
opposite = TRUE,
minorTickInterval = "auto",
minorGridLineDashStyle = "LongDashDotDot",
plotLines = list(
list(label = list(text = "Mid-year"),
color = "#FF0000",
width = 2,
value = 6))) %>%
hc_xAxis(plotBands = list(
list(from = 9, to = 12, color = "rgba(100, 0, 0, 0.1)",
label = list(text = "This is a plotBand"))))
hc
A federal government budget: revenues and expenses.
library(highcharter)
hchart(b_revenues, "treemap", hcaes(x = Details, value = Budget2016, color = Budget2016))
hchart(b_expenses, "treemap", hcaes(x = Details, value = -Budget2016, color = -Budget2016))
The CAD/USD exchange rate.
suppressPackageStartupMessages(library(quantmod))
<- getSymbols("CAD/USD", src = "oanda", auto.assign = FALSE) x
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
library(highcharter)
hchart(x)
Subscriber churn (deactivation rate) in telecom.
library(survival)
<- survfit(Surv(tenure, Churn) ~ Contract, data = telco2)
fit
library(highcharter)
hchart(fit, ranges = TRUE)
library(survival)
<- coxph(Surv(tenure, Churn) ~ Contract,
cox_model method = 'efron',
data = telco2)
<- survfit(cox_model)
fit_cox_model
library(highcharter)
hchart(fit_cox_model, ranges = TRUE)
Each year, the Heritage Foundation along with the Wall Street Journal releases an Index of Economic Freedom where countries are measured with 12 metrics (12 ‘freedoms’).
Each Freedom metrics are percentages; 100 being the highest value:
library(highcharter)
hchart(princomp(liberty12, cor = TRUE))
With the mtcars
dataset.
library(highcharter)
hchart(cor(mtcars))
A choropleth of North America (region are filled with fake data).
library(highcharter)
hcmap("custom/usa-and-canada",
data = data_fake,
value = "value",
joinBy = c("hc-a2", "code"),
name = "Fake data",
dataLabels = list(enabled = TRUE, format = '{point.name}'),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix = " USD")) %>%
hc_mapNavigation(enabled = TRUE) %>%
hc_exporting(enabled = TRUE)
A bubble map with the same fake data.
hcmap("custom/usa-and-canada",
data = data_fake,
type = "mapbubble",
value = "value",
joinBy = c("hc-a2", "code"),
name = "Fake data",
dataLabels = list(enabled = TRUE, format = '{point.name}'),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix = " USD")) %>%
hc_mapNavigation(enabled = TRUE)