This a generic function, this means you can chart various R like numeric, histograms, character, factor, ts on the fly. The resulting chart is a highchart object so you can keep modifying with the implemented API.
Data Frames
This function works like qplot
: You pass the data,
choose the type of chart and then define the aesthetics for each
variable.
library(highcharter)
library(dplyr)
data(penguins, package = "palmerpenguins")
data(diamonds, economics_long, package = "ggplot2")
hchart(penguins, "scatter", hcaes(x = body_mass_g, y = flipper_length_mm , group = species))
## Rows: 5
## Columns: 3
## $ species <fct> Adelie, Adelie, Adelie, Chinstrap, Gentoo
## $ island <fct> Biscoe, Dream, Torgersen, Dream, Biscoe
## $ n <int> 44, 56, 52, 68, 124
Check automatically if the x column is date class:
Numeric & Histograms
x <- diamonds$price
hchart(x)
Character & Factor
x <- diamonds$cut
hchart(x, type = "column")
Igraph package
library(igraph)
N <- 40
net <- sample_gnp(N, p = 2 / N)
wc <- cluster_walktrap(net)
V(net)$label <- seq(N)
V(net)$name <- paste("I'm #", seq(N))
V(net)$page_rank <- round(page.rank(net)$vector, 2)
V(net)$betweenness <- round(betweenness(net), 2)
V(net)$degree <- degree(net)
V(net)$size <- V(net)$degree
V(net)$comm <- membership(wc)
V(net)$color <- colorize(membership(wc))
hchart(net, layout = layout_with_fr)
Quantmod package
The highstock extension is used to chart xts
and
xts ohlc
classes from the quantmod package.
library(quantmod)
x <- getSymbols("GOOG", auto.assign = FALSE)
hchart(x)
Matrix
data(volcano)
hchart(volcano) |> # changing default color
hc_colorAxis(
stops = color_stops(colors = c("#000004FF", "#56106EFF", "#BB3754FF", "#F98C0AFF", "#FCFFA4FF"))
)