Skip to contents

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.

Usage

hc_colorAxis(hc, ...)

Arguments

hc

A highchart htmlwidget object.

...

Arguments defined in https://api.highcharts.com/highcharts/colorAxis.

Examples


library(dplyr)

data(mpg, package = "ggplot2")

mpgman2 <- mpg |> 
  group_by(manufacturer, year) |> 
  dplyr::summarise(
    n = dplyr::n(),
    displ = mean(displ),
    .groups = "drop"
    )

mpgman2
#> # A tibble: 30 × 4
#>    manufacturer  year     n displ
#>    <chr>        <int> <int> <dbl>
#>  1 audi          1999     9  2.36
#>  2 audi          2008     9  2.73
#>  3 chevrolet     1999     7  4.97
#>  4 chevrolet     2008    12  5.12
#>  5 dodge         1999    16  4.32
#>  6 dodge         2008    21  4.42
#>  7 ford          1999    15  4.45
#>  8 ford          2008    10  4.66
#>  9 honda         1999     5  1.6 
#> 10 honda         2008     4  1.85
#> # … with 20 more rows

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)