Highcharter R Package Essentials for Easy Interactive Graphs

Highchart Interactive Pyramid Chart in R

This article describes how to create an interactive pyramid chart in R using the highcharter R package.

A pyramid chart has the form of a triangle with lines dividing it into sections. It used display related topics that need to be arranged in a way that shows hierarchical structure, as well as quantity or size.



Contents:

Loading required R package

# Load required R packages
library(dplyr)
library(highcharter) 
# Set highcharter options
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))

Data preparation

df <- data.frame(
        x = c(0, 1, 2, 3, 4),
        y = c(10, 19.4, 21.1, 14.4, 6.4),
        name = as.factor(c("grape", "olive", "guava", "nut", "pear"))
) %>%
  arrange(-y)
df
##   x    y  name
## 1 2 21.1 guava
## 2 1 19.4 olive
## 3 3 14.4   nut
## 4 0 10.0 grape
## 5 4  6.4  pear

Create a pyramid chart

hc <- df %>%
  hchart(
    "pyramid", hcaes(x = name, y = y),
    name = "Fruit consumption"
    )
hc



Version: Français

Highchart Interactive Funnel Chart in R (Prev Lesson)
(Next Lesson) Highchart Interactive Time Series Data Visualization in R
Back to Highcharter R Package Essentials for Easy Interactive Graphs

No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments