Highcharts have a rich API which allows you to have control of the entire chart, from title, subtitle to axis ticks, labels, annotations. We’ll review the main functions with simple examples.
- There’s not default arguments. All arguments need to be named.
- You can see more examples for arguments in https://api.highcharts.com/highcharts/.
If this is clear, we can continue.
Now, let’s create a simple chart:
library(highcharter) data("citytemp") hc <- highchart() |> hc_xAxis(categories = citytemp$month) |> hc_add_series( name = "Tokyo", data = citytemp$tokyo ) |> hc_add_series( name = "London", data = citytemp$london ) |> hc_add_series( name = "Other city", data = (citytemp$tokyo + citytemp$london)/2 ) hc
hc_chart you can define general chart options.
Now change type to column and add 3d effect.
A good chart always have at least title, right? Then you can do it better adding relevant information using a subtitle or caption, even link to the source of data:
hc |> hc_title( text = "This is the title of the chart" ) |> hc_subtitle( text = "This is an intereseting subtitle to give context for the chart or some interesting fact" ) |> hc_caption( text = "This is a long text to give some subtle details of the data which can be relevant to the reader. This is usually a long text that's why I'm trying to put a <i>loooooong</i> text.", useHTML = TRUE ) |> hc_credits( text = "Chart created using R and highcharter", href = "http://jkunst.com/highcharter", enabled = TRUE )
Usually is desirable get control or modify the behavior of the axis:
A good feature is
which you can use in both axis. For example:
hc |> hc_xAxis( plotLines = list( list( label = list(text = "This is a plotLine"), color = "#FF0000", width = 2, value = 4, # the zIndex is used to put the label text over the grid lines zIndex = 1 ) ) ) |> hc_yAxis( plotBands = list( list( from = 20, to = 50, color = hex_to_rgba("red", 0.1), label = list(text = "This is a plotBand"), # the zIndex is used to put the label text over the grid lines zIndex = 1 ) ) )