Title: | A Wrapper for the 'Highcharts' Library |
---|---|
Description: | A wrapper for the 'Highcharts' library including shortcut functions to plot R objects. 'Highcharts' <https://www.highcharts.com/> is a charting library offering numerous chart types with a simple configuration syntax. |
Authors: | Joshua Kunst [aut, cre], Nuno Agostinho [ctb] (hchart.survfit, densities and hc_add_series_scatter), Danton Noriega [ctb] (hcaes_), Charlie Joey Hadley [ctb] (hc_add_event_point improvement), Eduardo Flores [ctb] (First version hc_add_series_df_tidy), Dean Kilfoyle [ctb] (First version hc_add_series_boxplot), Adline Dsilva [ctb] (First version Matrix heatmap), Kamil Slowikowski [ctb] , Christian Minich [ctb] (hcaes mutate_mapping improvement), Jonathan Armond [ctb] (mutate_mapping bugfix), David Breuer [ctb] (download_map_data quiet parameter), Mauricio Vargas [ctb] (tests and gh-actions), Michael Yan [ctb] (Motivational example for treemap/sunburst data helper), Bart Oortwijn [ctb] (rjson option, hc_add_yAxis, and GH issues collaborator), Paul Campbell [ctb] (additional proxy methods) |
Maintainer: | Joshua Kunst <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.4.9000 |
Built: | 2024-11-08 04:59:44 UTC |
Source: | https://github.com/jbkunst/highcharter |
This data comes from the https://www.highcharts.com/ examples.
citytemp
citytemp
A data frame
with 12 observations and 5 variables.
month
: The months.
tokyo
: Tokyo's temperatures.
new_york
: New York's temperatures.
berlin
: Berlin's temperatures.
london
: London's temperatures.
This data comes from the https://www.highcharts.com/ examples.
citytemp_long
citytemp_long
A data frame
with 36 observations and 3 variables.
month
: The months.
citiy
: City.
temp
: Temperatures.
dataClasses
argument in hc_colorAxis
Function to create dataClasses
argument in hc_colorAxis
color_classes(breaks = NULL, colors = c("#440154", "#21908C", "#FDE725"))
color_classes(breaks = NULL, colors = c("#440154", "#21908C", "#FDE725"))
breaks |
A numeric vector |
colors |
A character string of colors (ordered) |
color_classes(c(0, 10, 20, 50))
color_classes(c(0, 10, 20, 50))
stops
argument in hc_colorAxis
Function to create stops
argument in hc_colorAxis
color_stops(n = 10, colors = c("#440154", "#21908C", "#FDE725"))
color_stops(n = 10, colors = c("#440154", "#21908C", "#FDE725"))
n |
A numeric indicating how much quantiles generate. |
colors |
A character string of colors (ordered) |
color_stops(5)
color_stops(5)
Create vector of color from vector
colorize(x, colors = c("#440154", "#21908C", "#FDE725"))
colorize(x, colors = c("#440154", "#21908C", "#FDE725"))
x |
A numeric, character or factor object. |
colors |
A character string of colors (ordered) to colorize |
colorize(runif(10)) colorize(LETTERS[rbinom(20, 5, 0.5)], c("#FF0000", "#00FFFF"))
colorize(runif(10)) colorize(LETTERS[rbinom(20, 5, 0.5)], c("#FF0000", "#00FFFF"))
Helper to transform data frame for boxplot highcharts format
data_to_boxplot( data, variable, group_var = NULL, group_var2 = NULL, add_outliers = FALSE, ... )
data_to_boxplot( data, variable, group_var = NULL, group_var2 = NULL, add_outliers = FALSE, ... )
data |
The data frame containing variables. |
variable |
The variable to calculate the box plot data. |
group_var |
A variable to split calculation |
group_var2 |
A second variable to create separate series. |
add_outliers |
A logical value indicating if outliers series should
be calculated. Default to |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
data(pokemon) dat <- data_to_boxplot(pokemon, height) highchart() %>% hc_xAxis(type = "category") %>% hc_add_series_list(dat) dat <- data_to_boxplot(pokemon, height, type_1, name = "height in meters") highchart() %>% hc_xAxis(type = "category") %>% hc_add_series_list(dat) ## Not run: ## End(Not run)
data(pokemon) dat <- data_to_boxplot(pokemon, height) highchart() %>% hc_xAxis(type = "category") %>% hc_add_series_list(dat) dat <- data_to_boxplot(pokemon, height, type_1, name = "height in meters") highchart() %>% hc_xAxis(type = "category") %>% hc_add_series_list(dat) ## Not run: ## End(Not run)
Helper to transform data frame for treemap/sunburst highcharts format
data_to_hierarchical( data, group_vars, size_var, colors = getOption("highcharter.color_palette") )
data_to_hierarchical( data, group_vars, size_var, colors = getOption("highcharter.color_palette") )
data |
data frame containing variables to organize each level of the treemap. |
group_vars |
Variables to generate treemap levels. |
size_var |
Variable to aggregate. |
colors |
Color to chart every item in the first level. |
## Not run: library(dplyr) data(gapminder, package = "gapminder") gapminder_2007 <- gapminder::gapminder %>% filter(year == max(year)) %>% mutate(pop_mm = round(pop / 1e6)) dout <- data_to_hierarchical(gapminder_2007, c(continent, country), pop_mm) hchart(dout, type = "sunburst") hchart(dout, type = "treemap") ## End(Not run)
## Not run: library(dplyr) data(gapminder, package = "gapminder") gapminder_2007 <- gapminder::gapminder %>% filter(year == max(year)) %>% mutate(pop_mm = round(pop / 1e6)) dout <- data_to_hierarchical(gapminder_2007, c(continent, country), pop_mm) hchart(dout, type = "sunburst") hchart(dout, type = "treemap") ## End(Not run)
Helper to transform data frame for sankey highcharts format
data_to_sankey(data = NULL)
data_to_sankey(data = NULL)
data |
A data frame |
## Not run: library(dplyr) data(diamonds, package = "ggplot2") diamonds2 <- select(diamonds, cut, color, clarity) data_to_sankey(diamonds2) hchart(data_to_sankey(diamonds2), "sankey", name = "diamonds") ## End(Not run)
## Not run: library(dplyr) data(diamonds, package = "ggplot2") diamonds2 <- select(diamonds, cut, color, clarity) data_to_sankey(diamonds2) hchart(data_to_sankey(diamonds2), "sankey", name = "diamonds") ## End(Not run)
Turn a date time vector to timestamp
format
datetime_to_timestamp(dt) dt_tstp(dt)
datetime_to_timestamp(dt) dt_tstp(dt)
dt |
Date or datetime vector |
datetime_to_timestamp( as.Date(c("2015-05-08", "2015-09-12"), format = "%Y-%m-%d" ) )
datetime_to_timestamp( as.Date(c("2015-05-08", "2015-09-12"), format = "%Y-%m-%d" ) )
Function to create annotations arguments from a data frame
df_to_annotations_labels(df, xAxis = 0, yAxis = 0)
df_to_annotations_labels(df, xAxis = 0, yAxis = 0)
df |
A data frame with |
xAxis |
Index (js 0-based) of the x axis to put the annotations. |
yAxis |
Index (js 0-based) of the y axis to put the annotations. |
df <- data.frame(text = c("hi", "bye"), x = c(0, 1), y = c(1, 0)) df_to_annotations_labels(df)
df <- data.frame(text = c("hi", "bye"), x = c(0, 1), y = c(1, 0)) df_to_annotations_labels(df)
The urls are listed in https://code.highcharts.com/mapdata/.
download_map_data(url = "custom/world.js", showinfo = FALSE, quiet = FALSE)
download_map_data(url = "custom/world.js", showinfo = FALSE, quiet = FALSE)
url |
The map's url. |
showinfo |
Show the properties of the downloaded map to know how
are the keys to add data in |
quiet |
Boolean parameter to turn off download messages (on by default). |
## Not run: mpdta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js") mpdta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js", quiet = TRUE ) str(mpdta, 1) ## End(Not run)
## Not run: mpdta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js") mpdta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js", quiet = TRUE ) str(mpdta, 1) ## End(Not run)
Function to export js file the configuration options
export_hc(hc, filename = NULL, as = "is", name = NULL)
export_hc(hc, filename = NULL, as = "is", name = NULL)
hc |
A |
filename |
String of the exported file. |
as |
String to define how to save the configuration options. One of 'is', 'container', 'variable'. |
name |
A variable used to put as name of the generated object if
|
fn <- "function(){ console.log('Category: ' + this.category); alert('Category: ' + this.category); }" hc <- highcharts_demo() %>% hc_plotOptions( series = list( cursor = "pointer", point = list( events = list( click = JS(fn) ) ) ) ) ## Not run: export_hc(hc, filename = "~/hc_is.js", as = "is") export_hc(hc, filename = "~/hc_vr.js", as = "variable", name = "objectname") export_hc(hc, filename = "~/hc_ct.js", as = "container", name = "#selectorid") ## End(Not run)
fn <- "function(){ console.log('Category: ' + this.category); alert('Category: ' + this.category); }" hc <- highcharts_demo() %>% hc_plotOptions( series = list( cursor = "pointer", point = list( events = list( click = JS(fn) ) ) ) ) ## Not run: export_hc(hc, filename = "~/hc_is.js", as = "is") export_hc(hc, filename = "~/hc_vr.js", as = "variable", name = "objectname") export_hc(hc, filename = "~/hc_ct.js", as = "container", name = "#selectorid") ## End(Not run)
Data from How I met Your Mother: Marshall's Favorite Bars.
favorite_bars
favorite_bars
A data frame
with 5 observations and 2 variables.
bar
: Bar's name.
percent
: In percentage of awesomeness
Data from How I met Your Mother: Marshall's Favorite Pies
favorite_pies
favorite_pies
A data frame
with 5 observations and 2 variables.
pie
: Bar's name.
percent
: In percentage of tastiness
Helper function to get the data inside the map data The urls are listed in https://code.highcharts.com/mapdata/.
get_data_from_map(mapdata)
get_data_from_map(mapdata)
mapdata |
A list obtained from |
dta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js") get_data_from_map(dta)
dta <- download_map_data("https://code.highcharts.com/mapdata/countries/us/us-ca-all.js") get_data_from_map(dta)
This function is used in hchart.data.frame
.
get_hc_series_from_df(data, type = NULL, ...)
get_hc_series_from_df(data, type = NULL, ...)
data |
A |
type |
The type of chart. Possible values are line, scatter, point, column. |
... |
Aesthetic mappings as |
highcharter:::get_hc_series_from_df(iris, type = "point", x = Sepal.Width)
highcharter:::get_hc_series_from_df(iris, type = "point", x = Sepal.Width)
Temperature information by years.
globaltemp
globaltemp
A data frame
with 1992 observations and 4 variables.
date
: Date.
lower
: Minimum temperature.
median
: Median temperature.
upper
: Maximum temperature.
http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/
Helper to add annotations from data frame or list
hc_add_annotation(hc, ...) hc_add_annotations(hc, x)
hc_add_annotation(hc, ...) hc_add_annotations(hc, x)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/annotations. |
x |
A |
The x
elements must have xValue
and yValue
elements
Add modules or plugin dependencies to highcharts objects
hc_add_dependency(hc, name = "plugins/annotations.js")
hc_add_dependency(hc, name = "plugins/annotations.js")
hc |
A |
name |
The partial path to the plugin or module,
example: |
See vignette("modules")
data(mpg, package = "ggplot2") hchart(mpg, "point", hcaes(displ, hwy), regression = TRUE, regressionSettings = list(type = "polynomial", order = 5, hideInLegend = TRUE) ) %>% hc_add_dependency("plugins/highcharts-regression.js") hchart(mpg, "point", hcaes(displ, hwy, group = drv), regression = TRUE) %>% hc_colors(c("#d35400", "#2980b9", "#2ecc71")) %>% hc_add_dependency("plugins/highcharts-regression.js")
data(mpg, package = "ggplot2") hchart(mpg, "point", hcaes(displ, hwy), regression = TRUE, regressionSettings = list(type = "polynomial", order = 5, hideInLegend = TRUE) ) %>% hc_add_dependency("plugins/highcharts-regression.js") hchart(mpg, "point", hcaes(displ, hwy, group = drv), regression = TRUE) %>% hc_colors(c("#d35400", "#2980b9", "#2ecc71")) %>% hc_add_dependency("plugins/highcharts-regression.js")
Helpers functions to get FontAwesome icons code
hc_add_dependency_fa(hc) fa_icon(iconname = "circle") fa_icon_mark(iconname = "circle")
hc_add_dependency_fa(hc) fa_icon(iconname = "circle") fa_icon_mark(iconname = "circle")
hc |
A |
iconname |
The icon's name |
When you use highcharter in a shiny app, for example
renderHighcharter('my_chart')
, you can access to the actions of the
user using and then use the hc_add_event_point
via the
my_chart
input (input$my_chart
). That's a way you can
use a chart as an input.
hc_add_event_point(hc, series = "series", event = "click") hc_add_event_series(hc, series = "series", event = "click")
hc_add_event_point(hc, series = "series", event = "click") hc_add_event_series(hc, series = "series", event = "click")
hc |
A |
series |
The name of type of series to apply the event. |
event |
The name of event: click, mouseOut, mouseOver. See https://api.highcharts.com/highcharts/plotOptions.areasplinerange.point.events.select for more details. |
Event details are accessible from hc_name_EventType, i.e. if a highchart is rendered against output$my_hc and and we wanted the coordinates of the user-clicked point we would use input$my_hc_click
Adding data to highchart objects
hc_add_series(hc, data = NULL, ...)
hc_add_series(hc, data = NULL, ...)
hc |
A |
data |
An R object like numeric, list, ts, xts, etc. |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
highchart() %>% hc_add_series(data = abs(rnorm(5)), type = "column") %>% hc_add_series(data = purrr::map(0:4, function(x) list(x, x)), type = "scatter", color = "orange")
highchart() %>% hc_add_series(data = abs(rnorm(5)), type = "column") %>% hc_add_series(data = purrr::map(0:4, function(x) list(x, x)), type = "scatter", color = "orange")
Shortcut for data series from a list of data series
hc_add_series_list(hc, x)
hc_add_series_list(hc, x)
hc |
A |
x |
A |
ds <- lapply(seq(5), function(x) { list(data = cumsum(rnorm(100, 2, 5)), name = x) }) highchart() %>% hc_plotOptions(series = list(marker = list(enabled = FALSE))) %>% hc_add_series_list(ds)
ds <- lapply(seq(5), function(x) { list(data = cumsum(rnorm(100, 2, 5)), name = x) }) highchart() %>% hc_plotOptions(series = list(marker = list(enabled = FALSE))) %>% hc_add_series_list(ds)
Add a map series
hc_add_series_map(hc, map, df, value, joinBy, ...)
hc_add_series_map(hc, map, df, value, joinBy, ...)
hc |
A |
map |
A |
df |
A |
value |
A string value with the name of the variable to chart. |
joinBy |
What property to join the |
... |
Additional shared arguments for the data series (https://api.highcharts.com/highcharts/series). |
This function force the highchart object to be map type.
library("dplyr") data("USArrests", package = "datasets") data("usgeojson") USArrests <- mutate(USArrests, state = rownames(USArrests)) highchart() %>% hc_title(text = "Violent Crime Rates by US State") %>% hc_subtitle(text = "Source: USArrests data") %>% hc_add_series_map(usgeojson, USArrests, name = "Murder arrests (per 100,000)", value = "Murder", joinBy = c("woename", "state"), dataLabels = list( enabled = TRUE, format = "{point.properties.postalcode}" ) ) %>% hc_colorAxis(stops = color_stops()) %>% hc_legend(valueDecimals = 0, valueSuffix = "%") %>% hc_mapNavigation(enabled = TRUE) ## Not run: data(worldgeojson, package = "highcharter") data("GNI2014", package = "treemap") highchart(type = "map") %>% hc_add_series_map(map = worldgeojson, df = GNI2014, value = "GNI", joinBy = "iso3") %>% hc_colorAxis(stops = color_stops()) %>% hc_tooltip( useHTML = TRUE, headerFormat = "", pointFormat = "this is {point.name} and have {point.population} people with gni of {point.GNI}" ) ## End(Not run)
library("dplyr") data("USArrests", package = "datasets") data("usgeojson") USArrests <- mutate(USArrests, state = rownames(USArrests)) highchart() %>% hc_title(text = "Violent Crime Rates by US State") %>% hc_subtitle(text = "Source: USArrests data") %>% hc_add_series_map(usgeojson, USArrests, name = "Murder arrests (per 100,000)", value = "Murder", joinBy = c("woename", "state"), dataLabels = list( enabled = TRUE, format = "{point.properties.postalcode}" ) ) %>% hc_colorAxis(stops = color_stops()) %>% hc_legend(valueDecimals = 0, valueSuffix = "%") %>% hc_mapNavigation(enabled = TRUE) ## Not run: data(worldgeojson, package = "highcharter") data("GNI2014", package = "treemap") highchart(type = "map") %>% hc_add_series_map(map = worldgeojson, df = GNI2014, value = "GNI", joinBy = "iso3") %>% hc_colorAxis(stops = color_stops()) %>% hc_tooltip( useHTML = TRUE, headerFormat = "", pointFormat = "this is {point.name} and have {point.population} people with gni of {point.GNI}" ) ## End(Not run)
hc_add_series for character and factor objects
## S3 method for class 'character' hc_add_series(hc, data, ...) ## S3 method for class 'factor' hc_add_series(hc, data, ...)
## S3 method for class 'character' hc_add_series(hc, data, ...) ## S3 method for class 'factor' hc_add_series(hc, data, ...)
hc |
A |
data |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
hc_add_series for data frames objects
## S3 method for class 'data.frame' hc_add_series(hc, data, type = NULL, mapping = hcaes(), fast = FALSE, ...)
## S3 method for class 'data.frame' hc_add_series(hc, data, type = NULL, mapping = hcaes(), fast = FALSE, ...)
hc |
A |
data |
A |
type |
The type of the series: line, bar, etc. |
mapping |
The mapping, same idea as |
fast |
convert to json during the composition of a highchart object |
... |
Arguments defined in https://api.highcharts.com/highcharts/chart. |
hc_add_series for density objects
## S3 method for class 'density' hc_add_series(hc, data, ...)
## S3 method for class 'density' hc_add_series(hc, data, ...)
hc |
A |
data |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
hc_add_series for forecast objects
## S3 method for class 'forecast' hc_add_series( hc, data, addOriginal = FALSE, addLevels = TRUE, fillOpacity = 0.1, name = NULL, ... )
## S3 method for class 'forecast' hc_add_series( hc, data, addOriginal = FALSE, addLevels = TRUE, fillOpacity = 0.1, name = NULL, ... )
hc |
A |
data |
A |
addOriginal |
Logical value to add the original series or not. |
addLevels |
Logical value to show predictions bands. |
fillOpacity |
The opacity of bands. |
name |
The name of the series. |
... |
Arguments defined in https://api.highcharts.com/highcharts/chart. |
hc_add_series for geo_json & geo_list objects
## S3 method for class 'geo_json' hc_add_series(hc, data, type = NULL, ...) ## S3 method for class 'geo_list' hc_add_series(hc, data, type = NULL, ...)
## S3 method for class 'geo_json' hc_add_series(hc, data, type = NULL, ...) ## S3 method for class 'geo_list' hc_add_series(hc, data, type = NULL, ...)
hc |
A |
data |
A |
type |
Type of series. Can be 'mapline', 'mapoint'. |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
hc_add_series for lm and loess objects
## S3 method for class 'lm' hc_add_series( hc, data, type = "line", color = "#5F83EE", fillOpacity = 0.1, ... ) ## S3 method for class 'loess' hc_add_series( hc, data, type = "line", color = "#5F83EE", fillOpacity = 0.1, ... )
## S3 method for class 'lm' hc_add_series( hc, data, type = "line", color = "#5F83EE", fillOpacity = 0.1, ... ) ## S3 method for class 'loess' hc_add_series( hc, data, type = "line", color = "#5F83EE", fillOpacity = 0.1, ... )
hc |
A |
data |
A |
type |
The type of the series: line, spline. |
color |
A stringr color. |
fillOpacity |
fillOpacity to the confidence interval. |
... |
Arguments defined in https://api.highcharts.com/highcharts/chart. |
hc_add_series
for numeric objectshc_add_series
for numeric objects
## S3 method for class 'numeric' hc_add_series(hc, data, ...)
## S3 method for class 'numeric' hc_add_series(hc, data, ...)
hc |
A |
data |
A numeric object |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
hc_add_series for time series objects
## S3 method for class 'ts' hc_add_series(hc, data, ...)
## S3 method for class 'ts' hc_add_series(hc, data, ...)
hc |
A |
data |
A time series |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
hc_add_series for xts objects
## S3 method for class 'xts' hc_add_series(hc, data, ...) ## S3 method for class 'ohlc' hc_add_series(hc, data, type = "candlestick", ...)
## S3 method for class 'xts' hc_add_series(hc, data, ...) ## S3 method for class 'ohlc' hc_add_series(hc, data, type = "candlestick", ...)
hc |
A |
data |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
type |
The way to show the |
Add highcharts themes to a highchart object.
hc_add_theme(hc, hc_thm)
hc_add_theme(hc, hc_thm)
hc |
A highchart object |
hc_thm |
A highchart theme object ( |
highchart() %>% hc_add_series( data = c( 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 ), type = "column" ) %>% hc_add_theme(hc_theme_sandsignika())
highchart() %>% hc_add_series( data = c( 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6 ), type = "column" ) %>% hc_add_theme(hc_theme_sandsignika())
A basic type of an annotation. It allows to add custom labels or shapes. The items can be tied to points, axis coordinates or chart pixel coordinates.
hc_annotations(hc, ...)
hc_annotations(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/annotations. |
# Ex 1 highchart() |> hc_add_series( data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4) ) |> hc_xAxis( tickInterval = 0.5, gridLineWidth = 1 ) |> hc_annotations( list( labels = list( list( point = list(x = 3, y = 129.2, xAxis = 0, yAxis = 0), text = "x: {x}<br/>y: {y}" ), list( point = list(x = 9, y = 194.1, xAxis = 0, yAxis = 0), text = "x: {x}<br/>y: {y}" ), list( point = list(x = 5, y = 100, xAxis = 0), text = "x: {x}<br/>y: {point.plotY} px" ), list( point = list(x = 0, y = 0), text = "x: {point.plotX} px<br/>y: {point.plotY} px" ) ) ) ) # Ex 2 df <- data.frame( x = 1:10, y = 1:10 ) highchart() |> hc_add_series(data = df, hcaes(x = x, y = y), type = "area") |> hc_annotations( list( labels = list( list(point = list(x = 5, y = 5, xAxis = 0, yAxis = 0), text = "Middle"), list(point = list(x = 1, y = 1, xAxis = 0, yAxis = 0), text = "Start") ) ) )
# Ex 1 highchart() |> hc_add_series( data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4) ) |> hc_xAxis( tickInterval = 0.5, gridLineWidth = 1 ) |> hc_annotations( list( labels = list( list( point = list(x = 3, y = 129.2, xAxis = 0, yAxis = 0), text = "x: {x}<br/>y: {y}" ), list( point = list(x = 9, y = 194.1, xAxis = 0, yAxis = 0), text = "x: {x}<br/>y: {y}" ), list( point = list(x = 5, y = 100, xAxis = 0), text = "x: {x}<br/>y: {point.plotY} px" ), list( point = list(x = 0, y = 0), text = "x: {point.plotX} px<br/>y: {point.plotY} px" ) ) ) ) # Ex 2 df <- data.frame( x = 1:10, y = 1:10 ) highchart() |> hc_add_series(data = df, hcaes(x = x, y = y), type = "area") |> hc_annotations( list( labels = list( list(point = list(x = 5, y = 5, xAxis = 0, yAxis = 0), text = "Middle"), list(point = list(x = 1, y = 1, xAxis = 0, yAxis = 0), text = "Start") ) ) )
Options for the Boost module. The Boost module allows certain series types to be rendered by WebGL instead of the default SVG. This allows hundreds of thousands of data points to be rendered in milliseconds. In addition to the WebGL rendering it saves time by skipping processing and inspection of the data wherever possible. This introduces some limitations to what features are available in boost mode. See the docs for details. In addition to the global boost option, each series has a boostThreshold that defines when the boost should kick in. Requires the modules/boost.js module.
hc_boost(hc, ...)
hc_boost(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/boost. |
# # Ex 1 # options(highcharter.rjson = FALSE) # # n <- 50000 # # x <- sin(4*2*pi*seq(n)/n) + rnorm(n)/10 # # x <- round(x, 3) # # plot(x) # # hc1 <- highchart() |> # hc_chart(zoomType = "x") |> # hc_add_series(data = x) |> # hc_title(text = "No boost") |> # hc_boost( # enabled = FALSE # Default # ) # # hc1 # # # Boost is a stripped-down renderer-in-a-module for Highcharts. It bypasses # # some of the standard Highcharts features (such as animation), and focuses # # on pushing as many points as possible as quickly as possible. # # hc2 <- highchart() |> # hc_chart(zoomType = "x") |> # hc_add_series(data = x) |> # hc_title(text = "With boost") |> # hc_boost(enabled = TRUE) # # hc2 # # # # # Ex 2 # # library(MASS) # # # # n <- 20000 # # # # sigma <- matrix(c(10,3,3,2),2,2) # # sigma # # # # mvr <- round(mvrnorm(n, rep(c(0, 0)), sigma), 2) # # # # vx <- ceiling(1+abs(max(mvr[, 1]))) # # vy <- ceiling(1+abs(max(mvr[, 2]))) # # # # # unnamed list # # ds <- list_parse2(as.data.frame(mvr)) # # # # highchart() |> # # hc_chart(zoomType = "xy") |> # # hc_xAxis(min = -vx, max = vx) |> # # hc_yAxis(min = -vy, max = vy) |> # # hc_add_series( # # data = ds, #list # # type = "scatter", # # name = "A lot of points!", # # color = 'rgba(0,0,0,0.1)', # # marker = list(radius = 2) # # ) |> # # hc_boost( # # enabled = TRUE # # ) # # # # dat <- as.data.frame(mvr) # # names(dat) <- c("x", "y") # # # # highchart() |> # # hc_chart(zoomType = "xy") |> # # hc_xAxis(min = -vx, max = vx) |> # # hc_yAxis(min = -vy, max = vy) |> # # hc_add_series( # # data = dat, # # type = "scatter", # # hcaes(x, y), # # name = "A lot of points!", # # color = 'rgba(0,0,0,0.1)', # # marker = list(radius = 2) # # ) |> # # hc_boost(enabled = TRUE) # # # # # Ex3 # # N <- 1000000 # # n <- 5 # # s <- seq(n) # # s <- s/(max(s) + min(s)) # # s <- round(s, 2) # # # # series <- s |> # # purrr::map(~ stats::arima.sim(round(N/n), model = list(ar = .x)) + .x * n * 20) |> # # purrr::map(as.vector) |> # # purrr::map(round, 2) |> # # purrr::map(~ list(data = .x)) # # # # highchart() |> # # hc_add_series_list(series) |> # # hc_chart(zoomType = "x") |> # # hc_boost(enabled = TRUE)
# # Ex 1 # options(highcharter.rjson = FALSE) # # n <- 50000 # # x <- sin(4*2*pi*seq(n)/n) + rnorm(n)/10 # # x <- round(x, 3) # # plot(x) # # hc1 <- highchart() |> # hc_chart(zoomType = "x") |> # hc_add_series(data = x) |> # hc_title(text = "No boost") |> # hc_boost( # enabled = FALSE # Default # ) # # hc1 # # # Boost is a stripped-down renderer-in-a-module for Highcharts. It bypasses # # some of the standard Highcharts features (such as animation), and focuses # # on pushing as many points as possible as quickly as possible. # # hc2 <- highchart() |> # hc_chart(zoomType = "x") |> # hc_add_series(data = x) |> # hc_title(text = "With boost") |> # hc_boost(enabled = TRUE) # # hc2 # # # # # Ex 2 # # library(MASS) # # # # n <- 20000 # # # # sigma <- matrix(c(10,3,3,2),2,2) # # sigma # # # # mvr <- round(mvrnorm(n, rep(c(0, 0)), sigma), 2) # # # # vx <- ceiling(1+abs(max(mvr[, 1]))) # # vy <- ceiling(1+abs(max(mvr[, 2]))) # # # # # unnamed list # # ds <- list_parse2(as.data.frame(mvr)) # # # # highchart() |> # # hc_chart(zoomType = "xy") |> # # hc_xAxis(min = -vx, max = vx) |> # # hc_yAxis(min = -vy, max = vy) |> # # hc_add_series( # # data = ds, #list # # type = "scatter", # # name = "A lot of points!", # # color = 'rgba(0,0,0,0.1)', # # marker = list(radius = 2) # # ) |> # # hc_boost( # # enabled = TRUE # # ) # # # # dat <- as.data.frame(mvr) # # names(dat) <- c("x", "y") # # # # highchart() |> # # hc_chart(zoomType = "xy") |> # # hc_xAxis(min = -vx, max = vx) |> # # hc_yAxis(min = -vy, max = vy) |> # # hc_add_series( # # data = dat, # # type = "scatter", # # hcaes(x, y), # # name = "A lot of points!", # # color = 'rgba(0,0,0,0.1)', # # marker = list(radius = 2) # # ) |> # # hc_boost(enabled = TRUE) # # # # # Ex3 # # N <- 1000000 # # n <- 5 # # s <- seq(n) # # s <- s/(max(s) + min(s)) # # s <- round(s, 2) # # # # series <- s |> # # purrr::map(~ stats::arima.sim(round(N/n), model = list(ar = .x)) + .x * n * 20) |> # # purrr::map(as.vector) |> # # purrr::map(round, 2) |> # # purrr::map(~ list(data = .x)) # # # # highchart() |> # # hc_add_series_list(series) |> # # hc_chart(zoomType = "x") |> # # hc_boost(enabled = TRUE)
General options for the chart.
hc_chart(hc, ...)
hc_chart(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/chart. |
hc <- highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_add_series(name = "London", data = sample(1:12) + 10) hc hc |> hc_chart( type = "column", options3d = list(enabled = TRUE, beta = 15, alpha = 15) ) hc |> hc_chart( borderColor = "#EBBA95", borderRadius = 10, borderWidth = 2, backgroundColor = list( linearGradient = c(0, 0, 500, 500), stops = list( list(0, 'rgb(255, 255, 255)'), list(1, 'rgb(200, 200, 255)') ) ) )
hc <- highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_add_series(name = "London", data = sample(1:12) + 10) hc hc |> hc_chart( type = "column", options3d = list(enabled = TRUE, beta = 15, alpha = 15) ) hc |> hc_chart( borderColor = "#EBBA95", borderRadius = 10, borderWidth = 2, backgroundColor = list( linearGradient = c(0, 0, 500, 500), stops = list( list(0, 'rgb(255, 255, 255)'), list(1, 'rgb(200, 200, 255)') ) ) )
A color axis for series. Visually, the color axis will appear as a gradient or as separate items inside the legend, depending on whether the axis is scalar or based on data classes. For supported color formats, see the docs article about colors. A scalar color axis is represented by a gradient. The colors either range between the minColor and the maxColor, or for more fine grained control the colors can be defined in stops. Often times, the color axis needs to be adjusted to get the right color spread for the data. In addition to stops, consider using a logarithmic axis type, or setting min and max to avoid the colors being determined by outliers. When dataClasses are used, the ranges are subdivided into separate classes like categories based on their values. This can be used for ranges between two values, but also for a true category. However, when your data is categorized, it may be as convenient to add each category to a separate series. Color axis does not work with: sankey, sunburst, dependencywheel, networkgraph, wordcloud, venn, gauge and solidgauge series types. Since v7.2.0 colorAxis can also be an array of options objects. See the Axis object for programmatic access to the axis.
hc_colorAxis(hc, ...)
hc_colorAxis(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/colorAxis. |
library(dplyr) data(mpg, package = "ggplot2") mpgman2 <- mpg |> group_by(manufacturer, year) |> dplyr::summarise( n = dplyr::n(), displ = mean(displ), .groups = "drop" ) mpgman2 hchart( mpgman2, "column", hcaes(x = manufacturer, y = n, group = year), colorKey = "displ", # color = c("#FCA50A", "#FCFFA4"), name = c("Year 1999", "Year 2008") ) |> hc_colorAxis(min = 0, max = 5) # defaults to yAxis hchart(iris, "point", hcaes(Sepal.Length, Sepal.Width)) |> hc_colorAxis( minColor = "red", maxColor = "blue" ) # Ex2 n <- 5 stops <- data.frame( q = 0:n/n, c = c("#440154", "#414487", "#2A788E", "#22A884", "#7AD151", "#FDE725"), stringsAsFactors = FALSE ) stops <- list_parse2(stops) M <- round(matrix(rnorm(50*50), ncol = 50), 2) hchart(M) |> hc_colorAxis(stops = stops) # Ex3 hchart(volcano) |> hc_colorAxis(stops = stops, max = 200)
library(dplyr) data(mpg, package = "ggplot2") mpgman2 <- mpg |> group_by(manufacturer, year) |> dplyr::summarise( n = dplyr::n(), displ = mean(displ), .groups = "drop" ) mpgman2 hchart( mpgman2, "column", hcaes(x = manufacturer, y = n, group = year), colorKey = "displ", # color = c("#FCA50A", "#FCFFA4"), name = c("Year 1999", "Year 2008") ) |> hc_colorAxis(min = 0, max = 5) # defaults to yAxis hchart(iris, "point", hcaes(Sepal.Length, Sepal.Width)) |> hc_colorAxis( minColor = "red", maxColor = "blue" ) # Ex2 n <- 5 stops <- data.frame( q = 0:n/n, c = c("#440154", "#414487", "#2A788E", "#22A884", "#7AD151", "#FDE725"), stringsAsFactors = FALSE ) stops <- list_parse2(stops) M <- round(matrix(rnorm(50*50), ncol = 50), 2) hchart(M) |> hc_colorAxis(stops = stops) # Ex3 hchart(volcano) |> hc_colorAxis(stops = stops, max = 200)
An array containing the default colors for the chart's series. When all colors are used, new colors are pulled from the start again.
hc_colors(hc, colors)
hc_colors(hc, colors)
hc |
A |
colors |
A vector of colors. |
library(viridisLite) cols <- viridis(3) cols <- substr(cols, 0, 7) highchart() |> hc_add_series(data = sample(1:12)) |> hc_add_series(data = sample(1:12) + 10) |> hc_add_series(data = sample(1:12) + 20) |> hc_colors(cols)
library(viridisLite) cols <- viridis(3) cols <- substr(cols, 0, 7) highchart() |> hc_add_series(data = sample(1:12)) |> hc_add_series(data = sample(1:12) + 10) |> hc_add_series(data = sample(1:12) + 20) |> hc_colors(cols)
Highchart by default puts a credits label in the lower right corner of the chart. This can be changed using these options.
hc_credits(hc, ...)
hc_credits(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/credits. |
highchart() |> hc_xAxis(categories = citytemp$month) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_credits( enabled = TRUE, text = "htmlwidgets.org", href = "http://www.htmlwidgets.org/" )
highchart() |> hc_xAxis(categories = citytemp$month) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_credits( enabled = TRUE, text = "htmlwidgets.org", href = "http://www.htmlwidgets.org/" )
Options for drill down, the concept of inspecting increasingly high resolution data through clicking on chart items like columns or pie slices. The drilldown feature requires the drilldown.js file to be loaded, found in the modules directory of the download package, or online at code.highcharts.com/modules/drilldown.js.
hc_drilldown(hc, ...)
hc_drilldown(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/drilldown. |
library(highcharter) library(dplyr) library(purrr) df <- tibble( name = c("Animals", "Fruits"), y = c(5, 2), drilldown = tolower(name) ) df hc <- highchart() |> hc_title(text = "Basic drilldown") |> hc_xAxis(type = "category") |> hc_legend(enabled = FALSE) |> hc_plotOptions( series = list( boderWidth = 0, dataLabels = list(enabled = TRUE) ) ) |> hc_add_series( data = df, type = "column", hcaes(name = name, y = y), name = "Things", colorByPoint = TRUE ) dfan <- data.frame( name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"), value = c(4, 3, 1, 2, 1) ) dffru <- data.frame( name = c("Apple", "Organes"), value = c(4, 2) ) dsan <- list_parse2(dfan) dsfru <- list_parse2(dffru) hc <- hc |> hc_drilldown( allowPointDrilldown = TRUE, series = list( list( id = "animals", data = dsan ), list( id = "fruits", data = dsfru ) ) ) hc
library(highcharter) library(dplyr) library(purrr) df <- tibble( name = c("Animals", "Fruits"), y = c(5, 2), drilldown = tolower(name) ) df hc <- highchart() |> hc_title(text = "Basic drilldown") |> hc_xAxis(type = "category") |> hc_legend(enabled = FALSE) |> hc_plotOptions( series = list( boderWidth = 0, dataLabels = list(enabled = TRUE) ) ) |> hc_add_series( data = df, type = "column", hcaes(name = name, y = y), name = "Things", colorByPoint = TRUE ) dfan <- data.frame( name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"), value = c(4, 3, 1, 2, 1) ) dffru <- data.frame( name = c("Apple", "Organes"), value = c(4, 2) ) dsan <- list_parse2(dfan) dsfru <- list_parse2(dffru) hc <- hc |> hc_drilldown( allowPointDrilldown = TRUE, series = list( list( id = "animals", data = dsan ), list( id = "fruits", data = dsfru ) ) ) hc
elementId
Function to modify the id
for the container.
hc_elementId(hc, id = NULL)
hc_elementId(hc, id = NULL)
hc |
A |
id |
A string |
hchart(rnorm(10)) %>% hc_elementId("newid")
hchart(rnorm(10)) %>% hc_elementId("newid")
Options for the exporting module. For an overview on the matter, see the docs.
hc_exporting(hc, ...)
hc_exporting(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/exporting. |
highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_exporting( enabled = TRUE, # always enabled filename = "custom-file-name" )
highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_exporting( enabled = TRUE, # always enabled filename = "custom-file-name" )
HTML labels that can be positioned anywhere in the chart area. This option is deprecated since v7.1.2. Instead, use annotations that support labels.
hc_labels(hc, ...)
hc_labels(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/labels. |
highchart() |> hc_add_series(data = sample(1:12)) |> hc_labels( items = list( list( html = "<p>Some <b>important</b><br>text</p>" , style = list( left = "150%", top = "150%" ) ) ) )
highchart() |> hc_add_series(data = sample(1:12)) |> hc_labels( items = list( list( html = "<p>Some <b>important</b><br>text</p>" , style = list( left = "150%", top = "150%" ) ) ) )
The legend is a box containing a symbol and name for each series item or point item in the chart. Each series (or points in case of pie charts) is represented by a symbol and its name in the legend. It is possible to override the symbol creator function and create custom legend symbols.
hc_legend(hc, ...)
hc_legend(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/legend. |
A Highmaps legend by default contains one legend item per series, but if a colorAxis is defined, the axis will be displayed in the legend. Either as a gradient, or as multiple legend items for dataClasses.
highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_add_series(name = "London", data = sample(1:12) + 10) |> hc_add_series(name = "Other City", data = sample(1:12) + 20) |> hc_legend( align = "left", verticalAlign = "top", layout = "vertical", x = 0, y = 100 )
highchart() |> hc_xAxis(categories = month.abb) |> hc_add_series(name = "Tokyo", data = sample(1:12)) |> hc_add_series(name = "London", data = sample(1:12) + 10) |> hc_add_series(name = "Other City", data = sample(1:12) + 20) |> hc_legend( align = "left", verticalAlign = "top", layout = "vertical", x = 0, y = 100 )
The loading options control the appearance of the loading screen that covers the plot area on chart operations. This screen only appears after an explicit call to chart.showLoading(). It is a utility for developers to communicate to the end user that something is going on, for example while retrieving new data via an XHR connection. The "Loading..." text itself is not part of this configuration object, but part of the lang object.
hc_loading(hc, ...)
hc_loading(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/loading. |
highcharts_demo() |> hc_loading( hideDuration = 1000, showDuration = 1000 )
highcharts_demo() |> hc_loading( hideDuration = 1000, showDuration = 1000 )
The mapView options control the initial view of the chart, and how projection is set up for raw geoJSON maps (beta as of v9.3). To set the view dynamically after chart generation, see mapView.setView.
hc_mapView(hc, ...)
hc_mapView(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highmaps/mapView. |
map <- hcmap() map map |> hc_mapView(zoom = 10) |> hc_mapNavigation(enabled = TRUE)
map <- hcmap() map map |> hc_mapView(zoom = 10) |> hc_mapNavigation(enabled = TRUE)
The Motion Highcharts Plugin adds an interactive HTML5 player to any Highcharts chart (Highcharts, Highmaps and Highstock).
hc_motion(hc, enabled = TRUE, startIndex = 0, ...)
hc_motion(hc, enabled = TRUE, startIndex = 0, ...)
hc |
A |
enabled |
Enable the motion plugin. |
startIndex |
start index, default to 0. |
... |
Arguments defined in https://github.com/TorsteinHonsi/Motion-Highcharts-Plugin/wiki. |
The pane serves as a container for axes and backgrounds for circular gauges and polar charts.
hc_pane(hc, ...)
hc_pane(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/pane. |
highchart() |> hc_chart( type = "gauge", plotBackgroundColor = NULL, plotBackgroundImage = NULL, plotBorderWidth = 0, plotShadow = FALSE ) |> hc_title( text = "Speedometer" ) |> hc_pane( startAngle = -150, endAngle = 150, background = list(list( backgroundColor = list( linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1), stops = list( list(0, "#FFF"), list(1, "#333") ) ), borderWidth = 0, outerRadius = "109%" ), list( backgroundColor = list( linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1), stops = list( list(0, "#333"), list(1, "#FFF") ) ), borderWidth = 1, outerRadius = "107%" ), list( # default background ), list( backgroundColor = "#DDD", borderWidth = 0, outerRadius = "105%", innerRadius = "103%" )) ) |> hc_add_series( data = list(80), name = "speed", tooltip = list(valueSuffix = " km/h") ) |> hc_yAxis( min = 0, max = 200, minorTickInterval = "auto", minorTickWidth = 1, minorTickLength = 10, minorTickPosition = "inside", minorTickColor = "#666", tickPixelInterval = 30, tickWidth = 2, tickPosition = "inside", tickLength = 10, tickColor = "#666", labels = list( step = 2, rotation = "auto" ), title = list( text = "km/h" ), plotBands = list( list(from = 0, to = 120, color = "#55BF3B"), list(from = 120, to = 160, color = "#DDDF0D"), list(from = 160, to = 200, color = "#DF5353") ) )
highchart() |> hc_chart( type = "gauge", plotBackgroundColor = NULL, plotBackgroundImage = NULL, plotBorderWidth = 0, plotShadow = FALSE ) |> hc_title( text = "Speedometer" ) |> hc_pane( startAngle = -150, endAngle = 150, background = list(list( backgroundColor = list( linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1), stops = list( list(0, "#FFF"), list(1, "#333") ) ), borderWidth = 0, outerRadius = "109%" ), list( backgroundColor = list( linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1), stops = list( list(0, "#333"), list(1, "#FFF") ) ), borderWidth = 1, outerRadius = "107%" ), list( # default background ), list( backgroundColor = "#DDD", borderWidth = 0, outerRadius = "105%", innerRadius = "103%" )) ) |> hc_add_series( data = list(80), name = "speed", tooltip = list(valueSuffix = " km/h") ) |> hc_yAxis( min = 0, max = 200, minorTickInterval = "auto", minorTickWidth = 1, minorTickLength = 10, minorTickPosition = "inside", minorTickColor = "#666", tickPixelInterval = 30, tickWidth = 2, tickPosition = "inside", tickLength = 10, tickColor = "#666", labels = list( step = 2, rotation = "auto" ), title = list( text = "km/h" ), plotBands = list( list(from = 0, to = 120, color = "#55BF3B"), list(from = 120, to = 160, color = "#DDDF0D"), list(from = 160, to = 200, color = "#DF5353") ) )
The plotOptions is a wrapper object for config objects for each series type. The config objects for each series can also be overridden for each series item as given in the series array. Configuration options for the series are given in three levels. Options for all series in a chart are given in the plotOptions.series object. Then options for all series of a specific type are given in the plotOptions of that type, for example plotOptions.line. Next, options for one single series are given in the series array.
hc_plotOptions(hc, ...)
hc_plotOptions(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions. |
highchart() |> hc_add_series( data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4) ) |> hc_plotOptions( line = list( color = "blue", marker = list( fillColor = "white", lineWidth = 2, lineColor = NULL ) ) )
highchart() |> hc_add_series( data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4) ) |> hc_plotOptions( line = list( color = "blue", marker = list( fillColor = "white", lineWidth = 2, lineColor = NULL ) ) )
The range selector is a tool for selecting ranges to display within the chart. It provides buttons to select preconfigured ranges in the chart, like 1 day, 1 week, 1 month etc. It also provides input boxes where min and max dates can be manually input.
hc_rangeSelector(hc, ...)
hc_rangeSelector(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highstock/rangeSelector. |
hc <- highchart(type = "stock") |> hc_add_series(AirPassengers) hc hc |> hc_rangeSelector(enabled = FALSE) hc |> hc_rangeSelector( verticalAlign = "bottom", selected = 4 )
hc <- highchart(type = "stock") |> hc_add_series(AirPassengers) hc hc |> hc_rangeSelector(enabled = FALSE) hc |> hc_rangeSelector( verticalAlign = "bottom", selected = 4 )
Allows setting a set of rules to apply for different screen or chart sizes. Each rule specifies additional chart options.
hc_responsive(hc, ...)
hc_responsive(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/responsive. |
leg_500_opts <- list(enabled = FALSE) leg_900_opts <- list(align = "right", verticalAlign = "middle", layout = "vertical") # change the with of the container/windows to see the effect highchart() |> hc_add_series(data = cumsum(rnorm(100))) |> hc_responsive( rules = list( # remove legend if there is no much space list( condition = list(maxWidth = 500), chartOptions = list(legend = leg_500_opts) ), # put legend on the right when there is much space list( condition = list(minWidth = 900), chartOptions = list(legend = leg_900_opts) ) ) )
leg_500_opts <- list(enabled = FALSE) leg_900_opts <- list(align = "right", verticalAlign = "middle", layout = "vertical") # change the with of the container/windows to see the effect highchart() |> hc_add_series(data = cumsum(rnorm(100))) |> hc_responsive( rules = list( # remove legend if there is no much space list( condition = list(maxWidth = 500), chartOptions = list(legend = leg_500_opts) ), # put legend on the right when there is much space list( condition = list(minWidth = 900), chartOptions = list(legend = leg_900_opts) ) ) )
Removing series to highchart objects
hc_rm_series(hc, names = NULL)
hc_rm_series(hc, names = NULL)
hc |
A |
names |
The series's names to delete. |
The scrollbar is a means of panning over the X axis of a stock chart. Scrollbars can also be applied to other types of axes. Another approach to scrollable charts is the chart.scrollablePlotArea option that is especially suitable for simpler cartesian charts on mobile. In styled mode, all the presentational options for the scrollbar are replaced by the classes .highcharts-scrollbar-thumb, .highcharts-scrollbar-arrow, .highcharts-scrollbar-button, .highcharts-scrollbar-rifles and .highcharts-scrollbar-track.
hc_scrollbar(hc, ...)
hc_scrollbar(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highstock/scrollbar. |
highchart(type = "stock") |> hc_add_series(AirPassengers) |> hc_rangeSelector(selected = 4) |> hc_scrollbar( barBackgroundColor = "gray", barBorderRadius = 7, barBorderWidth = 0, buttonBackgroundColor = "gray", buttonBorderWidth = 0, buttonArrowColor = "yellow", buttonBorderRadius = 7, rifleColor = "yellow", trackBackgroundColor = "white", trackBorderWidth = 1, trackBorderColor = "silver", trackBorderRadius = 7 )
highchart(type = "stock") |> hc_add_series(AirPassengers) |> hc_rangeSelector(selected = 4) |> hc_scrollbar( barBackgroundColor = "gray", barBorderRadius = 7, barBorderWidth = 0, buttonBackgroundColor = "gray", buttonBorderWidth = 0, buttonArrowColor = "yellow", buttonBorderRadius = 7, rifleColor = "yellow", trackBackgroundColor = "white", trackBorderWidth = 1, trackBorderColor = "silver", trackBorderRadius = 7 )
Series options for specific data and the data itself. In TypeScript you have to cast the series options to specific series types, to get all possible options for a series.
hc_series(hc, ...)
hc_series(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/series. |
highchart() |> hc_series( list( name = "Tokyo", data = c(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6) ), list( name = "London", data = c(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8) ) )
highchart() |> hc_series( list( name = "Tokyo", data = c(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6) ), list( name = "London", data = c(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8) ) )
highchart
objectChanging the size of a highchart
object
hc_size(hc, width = NULL, height = NULL)
hc_size(hc, width = NULL, height = NULL)
hc |
A |
width |
A numeric input in pixels. |
height |
A numeric input in pixels. |
hc <- hchart(ts(rnorm(100)), showInLegend = FALSE) hc_size(hc, 200, 200)
hc <- hchart(ts(rnorm(100)), showInLegend = FALSE) hc_size(hc, 200, 200)
The chart's subtitle. This can be used both to display a subtitle below the main title, and to display random text anywhere in the chart. The subtitle can be updated after chart initialization through the Chart.setTitle method.
hc_subtitle(hc, ...)
hc_subtitle(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/subtitle. |
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "column" ) |> hc_subtitle( text = "And this is a subtitle with more information", align = "left", style = list(color = "#2b908f", fontWeight = "bold") )
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "column" ) |> hc_subtitle( text = "And this is a subtitle with more information", align = "left", style = list(color = "#2b908f", fontWeight = "bold") )
Highcharts is very flexible so you can modify every element of the chart. There are some exiting themes so you can apply style to charts with few lines of code.
hc_theme(...)
hc_theme(...)
... |
A list of named parameters. |
More examples and details in https://www.highcharts.com/docs/chart-design-and-style/themes.
hc <- highcharts_demo() hc thm <- hc_theme( colors = c("red", "green", "blue"), chart = list( backgroundColor = "#15C0DE" ), title = list( style = list( color = "#333333", fontFamily = "Erica One" ) ), subtitle = list( style = list( color = "#666666", fontFamily = "Shadows Into Light" ) ), legend = list( itemStyle = list( fontFamily = "Tangerine", color = "black" ), itemHoverStyle = list( color = "gray" ) ) ) hc_add_theme(hc, thm)
hc <- highcharts_demo() hc thm <- hc_theme( colors = c("red", "green", "blue"), chart = list( backgroundColor = "#15C0DE" ), title = list( style = list( color = "#333333", fontFamily = "Erica One" ) ), subtitle = list( style = list( color = "#666666", fontFamily = "Shadows Into Light" ) ), legend = list( itemStyle = list( fontFamily = "Tangerine", color = "black" ), itemHoverStyle = list( color = "gray" ) ) ) hc_add_theme(hc, thm)
Highcharts is very flexible so you can modify every element of the chart. There are some exiting themes so you can apply style to charts with few lines of code.
hc_theme_538(...) hc_theme_sparkline_vb(...) hc_theme_tufte2(...)
hc_theme_538(...) hc_theme_sparkline_vb(...) hc_theme_tufte2(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_538()) highcharts_demo() %>% hc_add_theme(hc_theme_sparkline_vb()) highchart() %>% hc_chart(type = "column") %>% hc_add_series(data = round(1 + abs(rnorm(12)), 2), showInLegend = FALSE) %>% hc_xAxis(categories = month.abb) %>% hc_add_theme(hc_theme_tufte2())
highcharts_demo() %>% hc_add_theme(hc_theme_538()) highcharts_demo() %>% hc_add_theme(hc_theme_sparkline_vb()) highchart() %>% hc_chart(type = "column") %>% hc_add_series(data = round(1 + abs(rnorm(12)), 2), showInLegend = FALSE) %>% hc_xAxis(categories = month.abb) %>% hc_add_theme(hc_theme_tufte2())
Alone theme for highcharts
hc_theme_alone(...)
hc_theme_alone(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_alone())
highcharts_demo() %>% hc_add_theme(hc_theme_alone())
Bloomberg Graphics theme for highcharts
hc_theme_bloom(...)
hc_theme_bloom(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_bloom())
highcharts_demo() %>% hc_add_theme(hc_theme_bloom())
Chalk theme for highcharts
hc_theme_chalk(...)
hc_theme_chalk(...)
... |
A named parameters to modify the theme. Chalk theme for highcharts was inspired by https://www.amcharts.com/demos/. |
highcharts_demo() %>% hc_add_theme(hc_theme_chalk())
highcharts_demo() %>% hc_add_theme(hc_theme_chalk())
Dark Unica theme for highcharts
hc_theme_darkunica(...)
hc_theme_darkunica(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_darkunica())
highcharts_demo() %>% hc_add_theme(hc_theme_darkunica())
Dotabuff theme for highcharts
hc_theme_db(...)
hc_theme_db(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_db())
highcharts_demo() %>% hc_add_theme(hc_theme_db())
Economist theme for highcharts
hc_theme_economist(...)
hc_theme_economist(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_economist())
highcharts_demo() %>% hc_add_theme(hc_theme_economist())
Elementary (OS) theme for highcharts was based on https://elementary.io
hc_theme_elementary(...)
hc_theme_elementary(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_elementary())
highcharts_demo() %>% hc_add_theme(hc_theme_elementary())
Firefox theme was inspired by https://mozilla.design/.
hc_theme_ffx(...)
hc_theme_ffx(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_ffx())
highcharts_demo() %>% hc_add_theme(hc_theme_ffx())
Flat and flatdark theme is inspired by https://github.com/chriskempson/base16 and https://github.com/Mikata-Project/ggthemr#flat
hc_theme_flat(...)
hc_theme_flat(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_flat())
highcharts_demo() %>% hc_add_theme(hc_theme_flat())
Flatdark theme for highcharts
hc_theme_flatdark(...)
hc_theme_flatdark(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_flatdark())
highcharts_demo() %>% hc_add_theme(hc_theme_flatdark())
Financial Times theme for highcharts
hc_theme_ft(...)
hc_theme_ft(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_ft())
highcharts_demo() %>% hc_add_theme(hc_theme_ft())
ggplot2 theme is based on https://ggplot2.tidyverse.org/.
hc_theme_ggplot2(...)
hc_theme_ggplot2(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_ggplot2())
highcharts_demo() %>% hc_add_theme(hc_theme_ggplot2())
Google theme for highcharts is based on https://books.google.com/ngrams/.
hc_theme_google(...)
hc_theme_google(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_google())
highcharts_demo() %>% hc_add_theme(hc_theme_google())
Grid Light theme for highcharts
hc_theme_gridlight(...)
hc_theme_gridlight(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_gridlight())
highcharts_demo() %>% hc_add_theme(hc_theme_gridlight())
Hand Drawn theme for highcharts. Inspired by https://www.amcharts.com/demos/.
hc_theme_handdrawn(...)
hc_theme_handdrawn(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_handdrawn())
highcharts_demo() %>% hc_add_theme(hc_theme_handdrawn())
hcrt theme is used for the documentation website.
hc_theme_hcrt(...)
hc_theme_hcrt(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_hcrt())
highcharts_demo() %>% hc_add_theme(hc_theme_hcrt())
Function to combine hc_theme objects.
hc_theme_merge(...)
hc_theme_merge(...)
... |
|
thm <- hc_theme_merge( hc_theme_darkunica(), hc_theme( chart = list( backgroundColor = "transparent", divBackgroundImage = "http://cdn.wall-pix.net/albums/art-3Dview/00025095.jpg" ), title = list( style = list( color = "white", fontFamily = "Erica One" ) ) ) )
thm <- hc_theme_merge( hc_theme_darkunica(), hc_theme( chart = list( backgroundColor = "transparent", divBackgroundImage = "http://cdn.wall-pix.net/albums/art-3Dview/00025095.jpg" ), title = list( style = list( color = "white", fontFamily = "Erica One" ) ) ) )
Monokai is a well know text editor theme.
hc_theme_monokai(...)
hc_theme_monokai(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_monokai())
highcharts_demo() %>% hc_add_theme(hc_theme_monokai())
For Null theme the axis are removed (visible = FALSE
).
hc_theme_null(...)
hc_theme_null(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_null())
highcharts_demo() %>% hc_add_theme(hc_theme_null())
Sand Signika theme for highcharts
hc_theme_sandsignika(...)
hc_theme_sandsignika(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_sandsignika())
highcharts_demo() %>% hc_add_theme(hc_theme_sandsignika())
Theme smpl design is inspired by https://github.com/hrbrmstr/hrbrmisc/blob/master/R/themes.r and color by https://materialui.co/flatuicolors.
hc_theme_smpl(...)
hc_theme_smpl(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_smpl())
highcharts_demo() %>% hc_add_theme(hc_theme_smpl())
Sparkline theme is based on https://www.highcharts.com/demo/sparkline and this post https://jkunst.com/blog/posts/2020-06-26-valuebox-and-sparklines/.
hc_theme_sparkline(...)
hc_theme_sparkline(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_sparkline())
highcharts_demo() %>% hc_add_theme(hc_theme_sparkline())
The superheroes theme is inspired by https://public.tableau.com/profile/ryansmith#!/vizhome/HeroesofNewYork/SuperheroesinNewYork
hc_theme_superheroes(...)
hc_theme_superheroes(...)
... |
A named parameters to modify the theme. |
highcharts_demo() %>% hc_add_theme(hc_theme_superheroes())
highcharts_demo() %>% hc_add_theme(hc_theme_superheroes())
Tufte theme for highcharts
hc_theme_tufte(...)
hc_theme_tufte(...)
... |
A named parameters to modify the theme. |
n <- 15 dta <- data.frame( x = 1:n + rnorm(n), y = 2 * 1:n + rnorm(n) ) highchart() %>% hc_chart(type = "scatter") %>% hc_add_series(data = list_parse(dta), showInLegend = FALSE) %>% hc_add_theme(hc_theme_tufte())
n <- 15 dta <- data.frame( x = 1:n + rnorm(n), y = 2 * 1:n + rnorm(n) ) highchart() %>% hc_chart(type = "scatter") %>% hc_add_series(data = list_parse(dta), showInLegend = FALSE) %>% hc_add_theme(hc_theme_tufte())
The chart's main title.
hc_title(hc, ...)
hc_title(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/title. |
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "column" ) |> hc_title( text = "This is a title with <i>margin</i> and <b>Strong or bold text</b>", margin = 20, align = "left", style = list(color = "#22A884", useHTML = TRUE) )
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "column" ) |> hc_title( text = "This is a title with <i>margin</i> and <b>Strong or bold text</b>", margin = 20, align = "left", style = list(color = "#22A884", useHTML = TRUE) )
Options for the tooltip that appears when the user hovers over a series or point.
hc_tooltip(hc, ..., sort = FALSE, table = FALSE)
hc_tooltip(hc, ..., sort = FALSE, table = FALSE)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/tooltip. |
sort |
Logical value to implement sort according |
table |
Logical value to implement table in tooltip: http://stackoverflow.com/a/22327749/829971. |
highchart() |> hc_add_series(data = sample(1:12)) |> hc_add_series(data = sample(1:12) + 10) |> hc_tooltip( crosshairs = TRUE, borderWidth = 5, sort = TRUE, table = TRUE )
highchart() |> hc_add_series(data = sample(1:12)) |> hc_add_series(data = sample(1:12) + 10) |> hc_tooltip( crosshairs = TRUE, borderWidth = 5, sort = TRUE, table = TRUE )
The X axis or category axis. Normally this is the horizontal axis, though if the chart is inverted this is the vertical axis. In case of multiple axes, the xAxis node is an array of configuration objects. See the Axis class for programmatic access to the axis.
hc_xAxis(hc, ...)
hc_xAxis(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/xAxis. |
In Highmaps, the axis is hidden, but it is used behind the scenes to control features like zooming and panning. Zooming is in effect the same as setting the extremes of one of the exes.
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "spline" ) |> hc_xAxis( title = list(text = "x Axis at top"), alternateGridColor = "#FDFFD5", opposite = TRUE, plotLines = list( list( label = list(text = "This is a plotLine"), color = "#FF0000", width = 2, value = 5.5 ) ) )
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "spline" ) |> hc_xAxis( title = list(text = "x Axis at top"), alternateGridColor = "#FDFFD5", opposite = TRUE, plotLines = list( list( label = list(text = "This is a plotLine"), color = "#FF0000", width = 2, value = 5.5 ) ) )
The Y axis or value axis. Normally this is the vertical axis, though if the chart is inverted this is the horizontal axis. In case of multiple axes, the yAxis node is an array of configuration objects. See the Axis object for programmatic access to the axis.
hc_yAxis(hc, ...)
hc_yAxis(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/yAxis. |
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "spline" ) |> hc_yAxis( title = list(text = "y Axis at right"), opposite = TRUE, alternateGridColor = "#FAFAFA", minorTickInterval = "auto", minorGridLineDashStyle = "LongDashDotDot", showFirstLabel = FALSE, showLastLabel = FALSE, plotBands = list( list( from = 13, to = 17, color = "rgba(100, 0, 0, 0.1)", label = list(text = "This is a plotBand") ) ) )
highchart() |> hc_add_series( data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6), type = "spline" ) |> hc_yAxis( title = list(text = "y Axis at right"), opposite = TRUE, alternateGridColor = "#FAFAFA", minorTickInterval = "auto", minorGridLineDashStyle = "LongDashDotDot", showFirstLabel = FALSE, showLastLabel = FALSE, plotBands = list( list( from = 13, to = 17, color = "rgba(100, 0, 0, 0.1)", label = list(text = "This is a plotBand") ) ) )
The Y axis or value axis. Normally this is the vertical axis,
though if the chart is inverted this is the horizontal axis.
Add yAxis allows to add multiple axis with a relative height between Y axis.
Based upon the relative
parameter the height of each Y axis is recalculated.
Otherwise the parameters are as supported by Y axis.
hc_yAxis_multiples(hc, ...) hc_xAxis_multiples(hc, ...) hc_zAxis_multiples(hc, ...) create_axis( naxis = 2, heights = 1, sep = 0.01, offset = 0, turnopposite = TRUE, ... ) create_yaxis(...) hc_add_yAxis(hc, ...)
hc_yAxis_multiples(hc, ...) hc_xAxis_multiples(hc, ...) hc_zAxis_multiples(hc, ...) create_axis( naxis = 2, heights = 1, sep = 0.01, offset = 0, turnopposite = TRUE, ... ) create_yaxis(...) hc_add_yAxis(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/yAxis. |
naxis |
Number of axis an integer. |
heights |
A numeric vector. This values will be normalized. |
sep |
A numeric value for the separation (in percentage) for the panes. |
offset |
A numeric value (in percentage). |
turnopposite |
A logical value to turn the side of each axis or not. |
highchart() %>% hc_yAxis_multiples(create_axis(naxis = 2, heights = c(2, 1))) %>% hc_add_series(data = c(1, 3, 2), yAxis = 0) %>% hc_add_series(data = c(20, 40, 10), yAxis = 1) highchart() %>% hc_yAxis_multiples(create_axis(naxis = 3, lineWidth = 2, title = list(text = NULL))) %>% hc_add_series(data = c(1, 3, 2)) %>% hc_add_series(data = c(20, 40, 10), type = "area", yAxis = 1) %>% hc_add_series(data = c(200, 400, 500), yAxis = 2) %>% hc_add_series(data = c(500, 300, 400), type = "areaspline", yAxis = 2) # Retrieve stock data to plot. aapl <- quantmod::getSymbols("AAPL", src = "yahoo", from = "2020-01-01", auto.assign = FALSE ) # Plot prices and volume with relative height. highchart(type = "stock") %>% hc_title(text = "AAPLE") %>% hc_add_series(aapl, yAxis = 0, showInLegend = FALSE) %>% hc_add_yAxis(nid = 1L, title = list(text = "Prices"), relative = 2) %>% hc_add_series(aapl[, "AAPL.Volume"], yAxis = 1, type = "column", showInLegend = FALSE) %>% hc_add_yAxis(nid = 2L, title = list(text = "Volume"), relative = 1)
highchart() %>% hc_yAxis_multiples(create_axis(naxis = 2, heights = c(2, 1))) %>% hc_add_series(data = c(1, 3, 2), yAxis = 0) %>% hc_add_series(data = c(20, 40, 10), yAxis = 1) highchart() %>% hc_yAxis_multiples(create_axis(naxis = 3, lineWidth = 2, title = list(text = NULL))) %>% hc_add_series(data = c(1, 3, 2)) %>% hc_add_series(data = c(20, 40, 10), type = "area", yAxis = 1) %>% hc_add_series(data = c(200, 400, 500), yAxis = 2) %>% hc_add_series(data = c(500, 300, 400), type = "areaspline", yAxis = 2) # Retrieve stock data to plot. aapl <- quantmod::getSymbols("AAPL", src = "yahoo", from = "2020-01-01", auto.assign = FALSE ) # Plot prices and volume with relative height. highchart(type = "stock") %>% hc_title(text = "AAPLE") %>% hc_add_series(aapl, yAxis = 0, showInLegend = FALSE) %>% hc_add_yAxis(nid = 1L, title = list(text = "Prices"), relative = 2) %>% hc_add_series(aapl[, "AAPL.Volume"], yAxis = 1, type = "column", showInLegend = FALSE) %>% hc_add_yAxis(nid = 2L, title = list(text = "Volume"), relative = 1)
The Z axis or depth axis for 3D plots. See the Axis class for programmatic access to the axis.
hc_zAxis(hc, ...)
hc_zAxis(hc, ...)
hc |
A |
... |
Arguments defined in https://api.highcharts.com/highcharts/zAxis. |
df <- data.frame( x = sample(1:5), y = sample(1:5), z = sample(1:5) ) highchart() |> hc_add_series(data = df, "scatter3d", hcaes(x = x, y = y, z = z)) |> hc_chart( type = "scatter3d", options3d = list( enabled = TRUE, alpha = 20, beta = 30, depth = 200, viewDistance = 5, frame = list( bottom = list( size = 1, color = "rgba(0,0,0,0.05)" ) ) ) ) |> hc_zAxis( title = list(text = "Z axis is here"), startOnTick = FALSE, tickInterval = 2, tickLength = 4, tickWidth = 1, gridLineColor = "red", gridLineDashStyle = "dot" )
df <- data.frame( x = sample(1:5), y = sample(1:5), z = sample(1:5) ) highchart() |> hc_add_series(data = df, "scatter3d", hcaes(x = x, y = y, z = z)) |> hc_chart( type = "scatter3d", options3d = list( enabled = TRUE, alpha = 20, beta = 30, depth = 200, viewDistance = 5, frame = list( bottom = list( size = 1, color = "rgba(0,0,0,0.05)" ) ) ) ) |> hc_zAxis( title = list(text = "Z axis is here"), startOnTick = FALSE, tickInterval = 2, tickLength = 4, tickWidth = 1, gridLineColor = "red", gridLineDashStyle = "dot" )
ggplot2::aes
Define aesthetic mappings.
Similar in spirit to ggplot2::aes
hcaes(x, y, ...)
hcaes(x, y, ...)
x , y , ...
|
List of name value pairs giving aesthetics to map to variables. The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named. |
hcaes(x = xval, color = colorvar, group = grvar)
hcaes(x = xval, color = colorvar, group = grvar)
ggplot2::aes_string
Define aesthetic mappings using strings.
Similar in spirit to ggplot2::aes_string
hcaes_string(x, y, ...) hcaes_(x, y, ...)
hcaes_string(x, y, ...) hcaes_(x, y, ...)
x , y , ...
|
List of name value pairs giving aesthetics to map to variables. The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named. |
hchart(mtcars, "point", hcaes_string("hp", "mpg", group = "cyl")) hcaes_string(x = "xval", color = "colorvar", group = "grvar")
hchart(mtcars, "point", hcaes_string("hp", "mpg", group = "cyl")) hcaes_string(x = "xval", color = "colorvar", group = "grvar")
Shortcut to make a boxplot
hcboxplot(x = NULL, var = NULL, var2 = NULL, outliers = TRUE, ...)
hcboxplot(x = NULL, var = NULL, var2 = NULL, outliers = TRUE, ...)
x |
A numeric vector. |
var |
A string vector same length of x. |
var2 |
A string vector same length of x. |
outliers |
A boolean value to show or not the outliers. |
... |
Additional arguments for the data series https://api.highcharts.com/highcharts/series. |
## Not run: hcboxplot(x = iris$Sepal.Length, var = iris$Species, color = "red") ## End(Not run)
## Not run: hcboxplot(x = iris$Sepal.Length, var = iris$Species, color = "red") ## End(Not run)
hchart
uses highchart
to draw a particular plot for an
object of a particular class in a single command. This defines the S3
generic that other classes and packages can extend.
hchart(object, ...)
hchart(object, ...)
object |
A R object. |
... |
Additional arguments for the data series (https://api.highcharts.com/highcharts/series). |
Run methods(hchart)
to see what objects are supported.
Plot survival curves using Highcharts
## S3 method for class 'survfit' hchart( object, ..., fun = NULL, markTimes = TRUE, symbol = "plus", markerColor = "black", ranges = FALSE, rangesOpacity = 0.3 )
## S3 method for class 'survfit' hchart( object, ..., fun = NULL, markTimes = TRUE, symbol = "plus", markerColor = "black", ranges = FALSE, rangesOpacity = 0.3 )
object |
A survfit object as returned from the |
... |
Extra parameters to pass to |
fun |
Name of function or function used to transform the survival curve:
|
markTimes |
Label curves marked at each censoring time? TRUE by default |
symbol |
Symbol to use as marker (plus sign by default) |
markerColor |
Color of the marker ("black" by default); use NULL to use the respective color of each series |
ranges |
Plot interval ranges? FALSE by default |
rangesOpacity |
Opacity of the interval ranges (0.3 by default) |
Highcharts object to plot survival curves
# Plot Kaplan-Meier curves require("survival") leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml) hchart(leukemia.surv) # Plot the cumulative hazard function lsurv2 <- survfit(Surv(time, status) ~ x, aml, type = "fleming") hchart(lsurv2, fun = "cumhaz") # Plot the fit of a Cox proportional hazards regression model fit <- coxph(Surv(futime, fustat) ~ age, data = ovarian) ovarian.surv <- survfit(fit, newdata = data.frame(age = 60)) hchart(ovarian.surv, ranges = TRUE)
# Plot Kaplan-Meier curves require("survival") leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml) hchart(leukemia.surv) # Plot the cumulative hazard function lsurv2 <- survfit(Surv(time, status) ~ x, aml, type = "fleming") hchart(lsurv2, fun = "cumhaz") # Plot the fit of a Cox proportional hazards regression model fit <- coxph(Surv(futime, fustat) ~ age, data = ovarian) ovarian.surv <- survfit(fit, newdata = data.frame(age = 60)) hchart(ovarian.surv, ranges = TRUE)
Shortcut to make icon arrays charts
hciconarray(labels, counts, rows = NULL, icons = NULL, size = 4, ...)
hciconarray(labels, counts, rows = NULL, icons = NULL, size = 4, ...)
labels |
A character vector |
counts |
A integer vector |
rows |
A integer to set |
icons |
A character vector same length (o length 1) as labels |
size |
Font size |
... |
Additional arguments for the data series https://api.highcharts.com/highcharts/series. |
Shortcut for create map from https://code.highcharts.com/mapdata/ collection.
hcmap( map = "custom/world", download_map_data = getOption("highcharter.download_map_data"), data = NULL, value = NULL, joinBy = NULL, ... )
hcmap( map = "custom/world", download_map_data = getOption("highcharter.download_map_data"), data = NULL, value = NULL, joinBy = NULL, ... )
map |
String indicating what map to chart, a list from https://code.highcharts.com/mapdata/. See examples. |
download_map_data |
A logical value whether to download
(add as a dependency) the map. Default |
data |
Optional data to make a choropleth, in case of use the joinBy and value are needed. |
value |
A string value with the name of the variable to chart. |
joinBy |
What property to join the |
... |
Additional shared arguments for the data series (https://api.highcharts.com/highcharts/series). |
options(highcharter.download_map_data = TRUE) # hcmap(nullColor = "#DADADA") # hcmap(nullColor = "#DADADA", download_map_data = FALSE) require(dplyr) data("USArrests", package = "datasets") USArrests <- mutate(USArrests, "woe-name" = rownames(USArrests)) # hcmap( # map = "countries/us/us-all", data = USArrests, # joinBy = "woe-name", value = "UrbanPop", name = "Urban Population" # ) # download_map_data = FALSE # hcmap( # map = "countries/us/us-all", data = USArrests, # joinBy = "woe-name", value = "UrbanPop", name = "Urban Population", # download_map_data = FALSE # )
options(highcharter.download_map_data = TRUE) # hcmap(nullColor = "#DADADA") # hcmap(nullColor = "#DADADA", download_map_data = FALSE) require(dplyr) data("USArrests", package = "datasets") USArrests <- mutate(USArrests, "woe-name" = rownames(USArrests)) # hcmap( # map = "countries/us/us-all", data = USArrests, # joinBy = "woe-name", value = "UrbanPop", name = "Urban Population" # ) # download_map_data = FALSE # hcmap( # map = "countries/us/us-all", data = USArrests, # joinBy = "woe-name", value = "UrbanPop", name = "Urban Population", # download_map_data = FALSE # )
Shortcut to create parallel coordinates
hcparcords(df, ...)
hcparcords(df, ...)
df |
A data frame object. |
... |
Additional shared arguments for the data series
(https://api.highcharts.com/highcharts/series) for the
|
require(viridisLite) n <- 15 hcparcords(head(mtcars, n), color = hex_to_rgba(magma(n), 0.5)) require(dplyr) data(iris) set.seed(123) iris <- sample_n(iris, 60) hcparcords(iris, color = colorize(iris$Species))
require(viridisLite) n <- 15 hcparcords(head(mtcars, n), color = hex_to_rgba(magma(n), 0.5)) require(dplyr) data(iris) set.seed(123) iris <- sample_n(iris, 60) hcparcords(iris, color = colorize(iris$Species))
Add point to a series of a higchartProxy object
hcpxy_add_point( proxy, id = NULL, point, redraw = TRUE, shift = FALSE, animation = TRUE )
hcpxy_add_point( proxy, id = NULL, point, redraw = TRUE, shift = FALSE, animation = TRUE )
proxy |
A |
id |
A character vector indicating the |
point |
The point options. If options is a single number, a point with that y value is appended to the series. If it is an list, it will be interpreted as x and y values respectively. If it is an object, advanced options as outlined under series.data are applied |
redraw |
Whether to redraw the chart after the point is added. When adding more than one point, it is highly recommended that the redraw option be set to false, and instead Highcharts.Chart#redraw is explicitly called after the adding of points is finished. Otherwise, the chart will redraw after adding each point. |
shift |
If |
animation |
Whether to apply animation, and optionally animation configuration. |
Add data to higchartProxy element
hcpxy_add_series(proxy, data = NULL, ...)
hcpxy_add_series(proxy, data = NULL, ...)
proxy |
A |
data |
An R object supported by |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. |
Show or hide loading text for a higchartProxy object
hcpxy_loading(proxy, action = "show")
hcpxy_loading(proxy, action = "show")
proxy |
A |
action |
Single-element character vector indicating to |
Redraw a higchartProxy object
hcpxy_redraw(proxy)
hcpxy_redraw(proxy)
proxy |
A |
Remove point to a series of a higchartProxy object
hcpxy_remove_point(proxy, id = NULL, i = NULL, redraw = TRUE)
hcpxy_remove_point(proxy, id = NULL, i = NULL, redraw = TRUE)
proxy |
A |
id |
A character vector indicating the |
i |
The index of the point in the data array. Remember js is 0 based index. |
redraw |
Whether to redraw the chart after the point is added. When adding more than one point, it is highly recommended that the redraw option be set to false, and instead Highcharts.Chart#redraw is explicitly called after the adding of points is finished. Otherwise, the chart will redraw after adding each point. |
Remove series to higchartProxy element
hcpxy_remove_series(proxy, id = NULL, all = FALSE)
hcpxy_remove_series(proxy, id = NULL, all = FALSE)
proxy |
A |
id |
A character vector indicating the |
all |
A logical value to indicate to remove or not all series. The values
is used only when the value is |
Update data for a higchartProxy object
hcpxy_set_data( proxy, type, data, mapping = hcaes(), redraw = FALSE, animation = NULL, updatePoints = TRUE )
hcpxy_set_data( proxy, type, data, mapping = hcaes(), redraw = FALSE, animation = NULL, updatePoints = TRUE )
proxy |
A |
type |
series type (column, bar, line, etc) |
data |
dataframe of new data to send to chart |
mapping |
how data should be mapped using |
redraw |
boolean Whether to redraw the chart after the series is altered. If doing more operations on the chart, it is a good idea to set redraw to false and call hcpxy_redraw after. |
animation |
boolean When the updated data is the same length as the existing data, points will be updated by default, and animation visualizes how the points are changed. Set false to disable animation, or a configuration object to set duration or easing. |
updatePoints |
boolean When this is TRUE, points will be updated instead of replaced whenever possible. This occurs a) when the updated data is the same length as the existing data, b) when points are matched by their id's, or c) when points can be matched by X values. This allows updating with animation and performs better. In this case, the original array is not passed by reference. Set FALSE to prevent. |
Update options for a higchartProxy object
hcpxy_update(proxy, ...)
hcpxy_update(proxy, ...)
proxy |
A |
... |
Named options. |
Update options series in a higchartProxy object
hcpxy_update_point(proxy, id = NULL, id_point = NULL, ...)
hcpxy_update_point(proxy, id = NULL, id_point = NULL, ...)
proxy |
A |
id |
A character indicating the |
id_point |
A vector value indicating the point's index to update, (0 based). |
... |
Arguments defined in https://api.highcharts.com/class-reference/Highcharts.Point. The arguments will be the same for each series. So if you want update data it is used this function sequentially for each point |
Update options series in a higchartProxy object
hcpxy_update_series(proxy, id = NULL, ...)
hcpxy_update_series(proxy, id = NULL, ...)
proxy |
A |
id |
A character vector indicating the |
... |
Arguments defined in https://api.highcharts.com/highcharts/plotOptions.series. The arguments will be the same for each series. So if you want update data it is used this function sequentially for each series. |
Shortcut to make spkarlines
hcspark(x = NULL, type = NULL, ...)
hcspark(x = NULL, type = NULL, ...)
x |
A numeric vector. |
type |
Type sparkline: line, bar, etc. |
... |
Additional arguments for the data series https://api.highcharts.com/highcharts/series. |
set.seed(123) x <- cumsum(rnorm(10)) hcspark(x) hcspark(x, "columnn") hcspark(c(1, 4, 5), "pie") hcspark(x, type = "area")
set.seed(123) x <- cumsum(rnorm(10)) hcspark(x) hcspark(x, "columnn") hcspark(c(1, 4, 5), "pie") hcspark(x, type = "area")
This function helps to create highcharts treemaps from treemap
objects
from the package treemap
. NOTE: This function is deprecated. Please use hctreemap2
instead.
hctreemap(tm, ...)
hctreemap(tm, ...)
tm |
A |
... |
Additional shared arguments for the data series (https://api.highcharts.com/highcharts/series). |
## Not run: library("treemap") library("viridis") data(GNI2014) head(GNI2014) tm <- treemap(GNI2014, index = c("continent", "iso3"), vSize = "population", vColor = "GNI", type = "comp", palette = rev(viridis(6)), draw = FALSE ) hctreemap(tm, allowDrillToNode = TRUE, layoutAlgorithm = "squarified") %>% hc_title(text = "Gross National Income World Data") %>% hc_tooltip(pointFormat = "<b>{point.name}</b>:<br> Pop: {point.value:,.0f}<br> GNI: {point.valuecolor:,.0f}") ## End(Not run)
## Not run: library("treemap") library("viridis") data(GNI2014) head(GNI2014) tm <- treemap(GNI2014, index = c("continent", "iso3"), vSize = "population", vColor = "GNI", type = "comp", palette = rev(viridis(6)), draw = FALSE ) hctreemap(tm, allowDrillToNode = TRUE, layoutAlgorithm = "squarified") %>% hc_title(text = "Gross National Income World Data") %>% hc_tooltip(pointFormat = "<b>{point.name}</b>:<br> Pop: {point.value:,.0f}<br> GNI: {point.valuecolor:,.0f}") ## End(Not run)
This function helps create highcharts treemaps from data frames.
hctreemap2(data, group_vars, size_var, color_var = NULL, ...)
hctreemap2(data, group_vars, size_var, color_var = NULL, ...)
data |
data frame containing variables to organize each level of the treemap on |
group_vars |
vector of strings containing column names of variables to generate treemap levels from. the first listed column will specify the top level of the treemap. the unique values in each of these columns must have no intersection (including NAs). |
size_var |
string name of column containing numeric data to aggregate by |
color_var |
string name of column containing numeric data to color by. defaults to same column as |
... |
additional shared arguments for the data series (https://api.highcharts.com/highcharts/series). |
highchart plot object
## Not run: library(tidyverse) library(highcharter) library(RColorBrewer) tibble( index1 = sample(LETTERS[1:5], 500, replace = T), index2 = sample(LETTERS[6:10], 500, replace = T), index3 = sample(LETTERS[11:15], 500, replace = T), value = rpois(500, 5), color_value = rpois(500, 5) ) %>% hctreemap2( group_vars = c("index1", "index2", "index3"), size_var = "value", color_var = "color_value", layoutAlgorithm = "squarified", levelIsConstant = FALSE, levels = list( list(level = 1, dataLabels = list(enabled = TRUE)), list(level = 2, dataLabels = list(enabled = FALSE)), list(level = 3, dataLabels = list(enabled = FALSE)) ) ) %>% hc_colorAxis( minColor = brewer.pal(7, "Greens")[1], maxColor = brewer.pal(7, "Greens")[7] ) %>% hc_tooltip(pointFormat = "<b>{point.name}</b>:<br> Value: {point.value:,.0f}<br> Color Value: {point.colorValue:,.0f}") ## End(Not run)
## Not run: library(tidyverse) library(highcharter) library(RColorBrewer) tibble( index1 = sample(LETTERS[1:5], 500, replace = T), index2 = sample(LETTERS[6:10], 500, replace = T), index3 = sample(LETTERS[11:15], 500, replace = T), value = rpois(500, 5), color_value = rpois(500, 5) ) %>% hctreemap2( group_vars = c("index1", "index2", "index3"), size_var = "value", color_var = "color_value", layoutAlgorithm = "squarified", levelIsConstant = FALSE, levels = list( list(level = 1, dataLabels = list(enabled = TRUE)), list(level = 2, dataLabels = list(enabled = FALSE)), list(level = 3, dataLabels = list(enabled = FALSE)) ) ) %>% hc_colorAxis( minColor = brewer.pal(7, "Greens")[1], maxColor = brewer.pal(7, "Greens")[7] ) %>% hc_tooltip(pointFormat = "<b>{point.name}</b>:<br> Value: {point.value:,.0f}<br> Color Value: {point.colorValue:,.0f}") ## End(Not run)
Transform colors from hexadecimal format to rgba hc notation
hex_to_rgba(x, alpha = 1)
hex_to_rgba(x, alpha = 1)
x |
colors in hexadecimal format |
alpha |
alpha |
hex_to_rgba(x <- c("#440154", "#21908C", "#FDE725", "red"))
hex_to_rgba(x <- c("#440154", "#21908C", "#FDE725", "red"))
This function creates a Highchart chart using htmlwidgets. The widget can be rendered on HTML pages generated from R Markdown, Shiny, or other applications.
highchart( hc_opts = list(), theme = getOption("highcharter.theme"), type = "chart", width = NULL, height = NULL, elementId = NULL, google_fonts = getOption("highcharter.google_fonts") )
highchart( hc_opts = list(), theme = getOption("highcharter.theme"), type = "chart", width = NULL, height = NULL, elementId = NULL, google_fonts = getOption("highcharter.google_fonts") )
hc_opts |
A |
theme |
A |
type |
A character value to set if use Highchart, Highstock or
Highmap. Options are |
width |
A numeric input in pixels. |
height |
A numeric input in pixels. |
elementId |
Use an explicit element ID for the widget. |
google_fonts |
A boolean value. If TRUE (default), adds a reference to the
Google Fonts API to the HTML head, downloading CSS for the font families
defined in the Highcharts theme from https://fonts.googleapis.com. Set to
FALSE if you load your own fonts using CSS. This option as default is
controlled by |
This widgets don't support options yet.
highchart2( hc_opts = list(), theme = getOption("highcharter.theme"), type = "chart", width = NULL, height = NULL, elementId = NULL, google_fonts = getOption("highcharter.google_fonts") ) highchartzero( hc_opts = list(), theme = NULL, width = NULL, height = NULL, elementId = NULL )
highchart2( hc_opts = list(), theme = getOption("highcharter.theme"), type = "chart", width = NULL, height = NULL, elementId = NULL, google_fonts = getOption("highcharter.google_fonts") ) highchartzero( hc_opts = list(), theme = NULL, width = NULL, height = NULL, elementId = NULL )
hc_opts |
A |
theme |
A |
type |
A character value to set if use Highchart, Highstock or
Highmap. Options are |
width |
A numeric input in pixels. |
height |
A numeric input in pixels. |
elementId |
Use an explicit element ID for the widget. |
google_fonts |
A boolean value. If TRUE (default), adds a reference to the Google Fonts API to the HTML head, downloading CSS for the font families defined in the Highcharts theme from https://fonts.googleapis.com. Set to FALSE if you load your own fonts using CSS. |
This function creates a Highchart chart using htmlwidgets. The widget can be rendered on HTML pages generated from R Markdown, Shiny, or other applications.
htmlwidget
interface to the
Highcharts javascript chart libraryHighcharts https://www.highcharts.com/ is a mature javascript charting library. Highcharts provide a various type of charts, from scatters to heatmaps or treemaps.
Joshua Kunst (@jbkunst)
The following functions are imported and then re-exported from the highcharter package to avoid listing the magrittr as Depends of highcharter.
Widget output function for use in Shiny
highchartOutput(outputId, width = "100%", height = "400px") highchartOutput2(outputId, width = "100%", height = "400px") highchartOutputZ(outputId, width = "100%", height = "400px")
highchartOutput(outputId, width = "100%", height = "400px") highchartOutput2(outputId, width = "100%", height = "400px") highchartOutputZ(outputId, width = "100%", height = "400px")
outputId |
The name of the input. |
width |
A numeric input in pixels. |
height |
A numeric input in pixels. |
Send commands to a Highcharts instance in a Shiny app
highchartProxy(shinyId, session = shiny::getDefaultReactiveDomain())
highchartProxy(shinyId, session = shiny::getDefaultReactiveDomain())
shinyId |
Single-element character vector indicating the output ID of the chart to modify |
session |
The Shiny session object to which the map belongs; usually the default value will suffice. |
Chart a demo for testing themes
highcharts_demo()
highcharts_demo()
highcharts_demo()
highcharts_demo()
grid.arrange
from gridExtra
.Lays out highchart widgets into a "grid", similar to
grid.arrange
from gridExtra
.
hw_grid( ..., ncol = NULL, rowheight = NULL, add_htmlgrid_css = TRUE, browsable = TRUE )
hw_grid( ..., ncol = NULL, rowheight = NULL, add_htmlgrid_css = TRUE, browsable = TRUE )
... |
either individual |
ncol |
how many columns in the grid |
rowheight |
Height in px. |
add_htmlgrid_css |
A logical value to add or not |
browsable |
Logical value indicating if the returned object is converted
to an HTML object browsable using |
charts <- lapply(1:9, function(x) { hchart(ts(cumsum(rnorm(100)))) }) if (interactive()) { hw_grid(charts, rowheight = 300) }
charts <- lapply(1:9, function(x) { hchart(ts(cumsum(rnorm(100)))) }) if (interactive()) { hw_grid(charts, rowheight = 300) }
Check if a string vector is in hexadecimal color format
is.hexcolor(x)
is.hexcolor(x)
x |
A string vectors |
x <- c("#f0f0f0", "#FFf", "#99990000", "#00FFFFFF") is.hexcolor(x)
x <- c("#f0f0f0", "#FFf", "#99990000", "#00FFFFFF") is.hexcolor(x)
Reports whether x is a highchart object
is.highchart(x)
is.highchart(x)
x |
An object to test |
This functions are similar to rlist::list.parse
but this removes
names. NA
s are removed for compatibility with rjson::toJSON.
list_parse(df) list_parse2(df)
list_parse(df) list_parse2(df)
df |
A data frame to parse to list |
x <- data.frame(a = 1:3, type = c("A", "C", "B"), stringsAsFactors = FALSE) list_parse(x) list_parse2(x)
x <- data.frame(a = 1:3, type = c("A", "C", "B"), stringsAsFactors = FALSE) list_parse(x) list_parse2(x)
This data comes from the https://www.highcharts.com/ examples: https://www.highcharts.com/demo/3d-area-multiple
mountains_panorama
mountains_panorama
A data frame
with 91 observations and 3 variables.
place
: The place.
name
: Name.
heigth
: Heigth.
Modify data frame according to mapping
mutate_mapping(data, mapping, drop = FALSE)
mutate_mapping(data, mapping, drop = FALSE)
data |
A data frame object. |
mapping |
A mapping from |
drop |
A logical argument to you drop variables or not. Default is
|
df <- head(mtcars) mutate_mapping(data = df, mapping = hcaes(x = cyl, y = wt + cyl, group = gear)) mutate_mapping(data = df, mapping = hcaes(x = cyl, y = wt), drop = TRUE)
df <- head(mtcars) mutate_mapping(data = df, mapping = hcaes(x = cyl, y = wt + cyl, group = gear)) mutate_mapping(data = df, mapping = hcaes(x = cyl, y = wt), drop = TRUE)
Information about 898 pokemon.
pokemon
pokemon
A data frame
with 898 observations and 24 variables.
Function to generate iids
random_id(n = 1, length = 10)
random_id(n = 1, length = 10)
n |
Number of ids |
length |
Length of ids |
Widget render function for use in Shiny
renderHighchart(expr, env = parent.frame(), quoted = FALSE) renderHighchart2(expr, env = parent.frame(), quoted = FALSE) renderHighchartZ(expr, env = parent.frame(), quoted = FALSE)
renderHighchart(expr, env = parent.frame(), quoted = FALSE) renderHighchart2(expr, env = parent.frame(), quoted = FALSE) renderHighchartZ(expr, env = parent.frame(), quoted = FALSE)
expr |
A highchart expression. |
env |
A environment. |
quoted |
A boolean value. |
A sample using by Nadieh Bremer blocks. http://bl.ocks.org/nbremer/eb0d1fd4118b731d069e2ff98dfadc47.
stars
stars
A data frame
with 404 observations and 6 variables.
bv
: BV
absmag
: Magnitude
lum
: Luminosity
temp
: Temperature
radiussun
: Radius
distance
: Distance
Turn a string to id
format used in treemaps.
str_to_id(x) str_to_id_vec(x)
str_to_id(x) str_to_id_vec(x)
x |
A vector string. |
str_to_id(" A string _ with sd / sdg Underscores \ ")
str_to_id(" A string _ with sd / sdg Underscores \ ")
Helper to create charts in tooltips.
tooltip_chart(accesor = NULL, hc_opts = NULL, width = 250, height = 150)
tooltip_chart(accesor = NULL, hc_opts = NULL, width = 250, height = 150)
accesor |
A string indicating the name of the column where the data is. |
hc_opts |
A list of options using the https://api.highcharts.com/highcharts/ syntax. |
width |
A numeric input in pixels indicating the with of the tooltip. |
height |
A numeric input in pixels indicating the height of the tooltip. |
This function needs to be used in the pointFormatter
argument
inside of hc_tooltip
function an useHTML = TRUE
option.
require(dplyr) require(purrr) require(tidyr) require(gapminder) data(gapminder, package = "gapminder") gp <- gapminder %>% arrange(desc(year)) %>% distinct(country, .keep_all = TRUE) gp2 <- gapminder %>% nest(-country) %>% mutate( data = map(data, mutate_mapping, hcaes(x = lifeExp, y = gdpPercap), drop = TRUE), data = map(data, list_parse) ) %>% rename(ttdata = data) gptot <- left_join(gp, gp2) hc <- hchart( gptot, "point", hcaes( lifeExp, gdpPercap, name = country, size = pop, group = continent ) ) %>% hc_yAxis(type = "logarithmic") hc %>% hc_tooltip(useHTML = TRUE, pointFormatter = tooltip_chart(accesor = "ttdata")) hc %>% hc_tooltip(useHTML = TRUE, pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list(chart = list(type = "column")) )) hc %>% hc_tooltip( useHTML = TRUE, positioner = JS("function () { return { x: this.chart.plotLeft + 10, y: 10}; }"), pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list( title = list(text = "point.country"), xAxis = list(title = list(text = "lifeExp")), yAxis = list(title = list(text = "gdpPercap")) ) ) ) hc %>% hc_tooltip( useHTML = TRUE, pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list( legend = list(enabled = TRUE), series = list(list(color = "gray", name = "point.name")) ) ) )
require(dplyr) require(purrr) require(tidyr) require(gapminder) data(gapminder, package = "gapminder") gp <- gapminder %>% arrange(desc(year)) %>% distinct(country, .keep_all = TRUE) gp2 <- gapminder %>% nest(-country) %>% mutate( data = map(data, mutate_mapping, hcaes(x = lifeExp, y = gdpPercap), drop = TRUE), data = map(data, list_parse) ) %>% rename(ttdata = data) gptot <- left_join(gp, gp2) hc <- hchart( gptot, "point", hcaes( lifeExp, gdpPercap, name = country, size = pop, group = continent ) ) %>% hc_yAxis(type = "logarithmic") hc %>% hc_tooltip(useHTML = TRUE, pointFormatter = tooltip_chart(accesor = "ttdata")) hc %>% hc_tooltip(useHTML = TRUE, pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list(chart = list(type = "column")) )) hc %>% hc_tooltip( useHTML = TRUE, positioner = JS("function () { return { x: this.chart.plotLeft + 10, y: 10}; }"), pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list( title = list(text = "point.country"), xAxis = list(title = list(text = "lifeExp")), yAxis = list(title = list(text = "gdpPercap")) ) ) ) hc %>% hc_tooltip( useHTML = TRUE, pointFormatter = tooltip_chart( accesor = "ttdata", hc_opts = list( legend = list(enabled = TRUE), series = list(list(color = "gray", name = "point.name")) ) ) )
Helper to make table in tooltips for the pointFormat
parameter in hc_tooltip
tooltip_table(x, y, title = NULL, img = NULL, ...)
tooltip_table(x, y, title = NULL, img = NULL, ...)
x |
A string vector with description text |
y |
A string with accessors example: |
title |
A title tag with accessors or string |
img |
Image tag |
... |
html attributes for the table element |
x <- c("Income:", "Genre", "Runtime") y <- c( "$ {point.y}", "{point.series.options.extra.genre}", "{point.series.options.extra.runtime}" ) tooltip_table(x, y)
x <- c("Income:", "Genre", "Runtime") y <- c( "$ {point.y}", "{point.series.options.extra.genre}", "{point.series.options.extra.runtime}" ) tooltip_table(x, y)
This data comes from the highcharts and is used in highmaps examples.
unemployment
unemployment
A data.frame
with 3 variables and 3.216 observations.
code
: The county code.
name
: The county name.
value
: The unemployment.
This data comes from the https://code.highcharts.com/mapdata/countries/us/us-all-all.js and is used in highmaps examples.
uscountygeojson
uscountygeojson
A list
in geojson format.
This data comes from the https://code.highcharts.com/mapdata/countries/us/us-all.js and is used in highmaps examples.
usgeojson
usgeojson
A list
in geojson format.
The number of infected people by Measles, measured over 70-some years and across all 50 states. From the WSJ analysis: http://graphics.wsj.com/infectious-diseases-and-vaccines/
vaccines
vaccines
A data frame
with 3,876 observations and 3 variables.
year
: Year
state
: Name of the state
count
: Number of cases per 100,000 people. If the value is NA the count was 0.
Temperature information of San Francisco.
weather
weather
A data frame
with 365 observations and 4 variables.
date
: Day in date format.
min_temperaturec
: Minimum temperature.
max_temperaturec
: Maximun temperature.
mean_temperaturec
: Mean temperature.
This data comes from the https://code.highcharts.com/mapdata/custom/world.js and is used in highmaps examples.#'
worldgeojson
worldgeojson
A list
in geojson format.