Open In App

Data Visualization with Highcharter in R

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Highcharter is an R package that provides an interface to the Highcharts JavaScript library, enabling the creation of interactive and customizable charts. It supports a variety of chart types, such as line, bar and scatter charts and offers extensive customization options for appearance and behavior.

It allows users to build dynamic visualizations with features like zooming, panning, tooltips and interactive data exploration. It also offers flexibility in styling chart elements (axes, titles, legends) and configuring animations and data labels.

Key features include:

  1. Customizability: Users can adjust colors, fonts, labels and tooltips and add elements like legends and annotations.
  2. Interactivity: Highcharter charts enable real-time exploration with zooming, hovering and data point highlighting.
  3. Integration: Easily integrates with R packages like dplyr, tidyr and ggplot2.
  4. Compatibility: Supports various data formats (CSV, JSON, SQL) and languages (English, Spanish, French, German).
  5. Responsive design: Charts automatically adjust to different screen sizes, making them suitable for web and mobile applications.

Installing and Loading

To install and load the Highcharter library in R , we will use the install.packages() and library() function.

R
install.packages("highcharter")
library(highcharter)

Different Visualizations in Highcharter Library

We will explore afew examples of how highcharter can be used to create different types of charts in R programming language.

1. Line Chart

A line chart is a great way to visualize trends over time. With Highcharter, you can create a line chart using the hc_line() function, which takes a data frame as input and maps the x and y columns to the chart's x and y axes.

Example:

In this example, we create a data frame with two columns, date and sales and use highchart() to create a chart object. We map the date column to the x-axis using hc_xAxis() and then add a line series to the chart using hc_add_series(). The type = "line" argument specifies that we want to create a line chart.

R
library(highcharter)

data <- data.frame(
  date = seq(as.Date("2022/01/01"), by = "month", length.out = 12),
  sales = c(10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32)
)

highchart() %>%
  hc_xAxis(categories = data$date) %>%
  hc_add_series(data$sales, type = "line")

Output:

Line chart with Highcharter in R

2. Bubble Chart

A bubble chart is a great way to visualize three variables at once, where the size of the bubble represents the third variable. With Highcharter, you can create a bubble chart using the hc_bubble() function.

Example:

In this example, we create a data frame with three columns, x, y and z and use hc_bubble() to create a bubble chart. We customize the chart by specifying the name of the series, the maximum size of the bubbles and enabling data labels that display the value of the third variable. We also customize the x and y axes by adding titles to them.

R
library(highcharter)

data <- data.frame(
  x = rnorm(50),
  y = rnorm(50),
  z = runif(50, min = 5, max = 20)
)

highchart() %>%
  hc_add_series(data = data, type = "bubble", 
                 name = "Bubbles", 
                 maxSize = 20,
                 dataLabels = list(enabled = TRUE, format = "{point.z}")) %>%
  hc_xAxis(title = list(text = "X-axis")) %>%
  hc_yAxis(title = list(text = "Y-axis"))

Output:

Bubble chart with Highcharter in R

3. Bar Chart

A bar chart is used to compare values across categories. We can create a bar chart using the hc_column() function, which takes a data frame as input and maps the x and y columns to the chart's x and y axes.

Example:

In this example, we first create a data frame with two columns (category and value) representing the categories and values we want to plot. Then, we create a basic column chart using the hc_chart(type = "column") function and add a title to the chart with hc_title(). We specify the x-axis categories using hc_xAxis(categories = data$category) and add a y-axis title with hc_yAxis(title = list(text = "Value")). Finally, we add a series to the chart with hc_add_series(data = data$value, name = "Values"), specifying the data we want to plot and the series name.

R
data <- data.frame(
  category = c("A", "B", "C", "D"),
  value = c(10, 20, 30, 40)
)

highchart() %>%
  hc_chart(type = "column") %>%
  hc_title(text = "Example Bar Chart") %>%
  hc_xAxis(categories = data$category) %>%
  hc_yAxis(title = list(text = "Value")) %>%
  hc_add_series(data = data$value, name = "Values")

Output:

Bar chart with Highcharter in R

4. Heat map

A heatmap is used to visualize data in a matrix format, where values are represented by color intensity. In Highcharter, we can create a heatmap using the hc_chart(type = "heatmap") function along with hc_add_series(), where we provide a matrix or a data frame specifying the x and y coordinates and corresponding values.

Example:

In this example, we are using hc_add_series() to create a heatmap by passing the matrix mat as the data source. We define the color scale with hc_colorAxis() and customize the tooltip display using hc_tooltip(). The x- and y-axis titles are added with hc_xAxis() and hc_yAxis(), where we also set the axis categories using colnames(mat) and rownames(mat), respectively. The y-axis is reversed using the reversed argument and we add a chart title with hc_chart()

R
library(highcharter)
set.seed(123)
mat <- matrix(rnorm(100), ncol = 10)

highchart() %>%
  hc_add_series(data = mat, type = "heatmap") %>%
  hc_colorAxis(stops = color_stops(10, colors = c("#FFFFCC", "#800026"))) %>%
  hc_tooltip(pointFormat = "Value: {point.value:.2f}") %>%
  hc_xAxis(categories = colnames(mat), title = list(text = "X-Axis")) %>%
  hc_yAxis(categories = rownames(mat), title = list(text = "Y-Axis"), reversed = TRUE) %>%
  hc_chart(title = list(text = "Heatmap Title"))

Output


In this article, we explored the highcharter package in R for building interactive and customizable visualizations using the Highcharts JavaScript library. We looked at its syntax, features and chart types, including heatmaps and bar charts, to understand how it supports dynamic data presentation in R.


Next Article

Similar Reads