library(highcharter) options(highcharter.theme = hc_theme_hcrt(tooltip = list(valueDecimals = 2)))
let us start start with a simple example using hchart
function.
library(highcharter) # install.packages("palmerpenguins") data(penguins, package = "palmerpenguins") hchart( penguins, "scatter", hcaes(x = flipper_length_mm, y = bill_length_mm, group = species) )
Among its features {highcharter} can chart various objects depending of
its class with the generic hchart
function. In the next example x
is numeric:
x <- c(rnorm(10000), rnorm(1000, 4, 0.5)) hchart(x, name = "data", color = "#17b8b6")
One of the nicest class which hchart
can plot is the forecast
class from the {forecast} package.
library(forecast) airforecast <- forecast(auto.arima(AirPassengers), level = 95) hchart(airforecast)
See more examples of hchart
in vignette("hchart")
.
With {highcharter} you can use the highstock library which include sophisticated navigation options like:
It is easy make candlesticks or ohlc charts using time series data. For example, using data from {quantmod} package:
library(quantmod) x <- getSymbols("GOOG", auto.assign = FALSE) y <- getSymbols("AMZN", auto.assign = FALSE) highchart(type = "stock") |> hc_add_series(x) |> hc_add_series(y, type = "ohlc")
We can chart maps elements and choropleth using the highmaps and build interactive maps to display data linked to geographic objects.
data(GNI2014, package = "treemap") hcmap( "custom/world-robinson-lowres", data = GNI2014, name = "Gross national income per capita", value = "GNI", borderWidth = 0, nullColor = "#d3d3d3", joinBy = c("iso-a3", "iso3") ) |> hc_colorAxis( stops = color_stops(colors = viridisLite::inferno(10, begin = 0.1)), type = "logarithmic" )
Since you know the basics now it could be interesting:
vignette("showcase")
and look everything that can be
done with the {highcharter} package.vignette("highcharts-api")
.vignette("highcharts")
.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.