Highcharter R Package Essentials for Easy Interactive Graphs

Highchart Interactive Area Plot in R

This article describes how to create interactive area plots using the highcharter R package.



Contents:

Loading required R packages

library(tidyverse)
library(highcharter) 

Data preparation

data("diamonds", package = "ggplot2")

df <- diamonds %>%
  group_by(cut)%>%
  count()
head(df, 4)
## # A tibble: 4 x 2
## # Groups:   cut [4]
##   cut           n
##   <ord>     <int>
## 1 Fair       1610
## 2 Good       4906
## 3 Very Good 12082
## 4 Premium   13791
df2 <- diamonds %>%
  group_by(cut, color)%>%
  count()
head(df2, 4)
## # A tibble: 4 x 3
## # Groups:   cut, color [4]
##   cut   color     n
##   <ord> <ord> <int>
## 1 Fair  D       163
## 2 Fair  E       224
## 3 Fair  F       312
## 4 Fair  G       314

Basic area plots

hc <- df %>% 
  hchart(
  'area', hcaes(x = cut, y = n),
  color = "steelblue"
  ) 
hc

Area plot with multiple groups

hc <- df2 %>% 
  hchart('area', hcaes(x = 'cut', y = 'n', group = "color"))
hc

Spline: Line with polynomial interpolation

hc <- df2 %>% 
  hchart('areaspline', hcaes(x = 'cut', y = 'n', group = "color"))
hc



Version: Français

Highchart Interactive Density and Histogram Plots in R (Prev Lesson)
(Next Lesson) Highchart Interactive Treemap 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