Highcharter R Package Essentials for Easy Interactive Graphs

Highchart Interactive Advanced Graphics in R

You will learn how to use the highcharter R package for creating interactive plots from the results of advanced statistical methods, such as:

  • Network analysis
  • Survival models
  • Principal component analysis
  • Correlation matrix
  • Distance matrix


Contents:

Prerequisites

# Load required R packages
library(tidyverse)
library(highcharter) 

# Set highcharter options
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))

Network analysis

library(igraph)
N <- 40

net <- sample_gnp(N, p = 2 / N)
wc <- cluster_walktrap(net)

V(net)$label <- seq(N)
V(net)$name <- paste("I'm #", seq(N))
V(net)$page_rank <- round(page.rank(net)$vector, 2)
V(net)$betweenness <- round(betweenness(net), 2)
V(net)$degree <- degree(net)
V(net)$size <- V(net)$degree
V(net)$comm <- membership(wc)
V(net)$color <- colorize(membership(wc))

hc <- hchart(net, layout = layout_with_fr)
hc

Survival models

library(survival)

data(lung)
lung <- mutate(lung, sex = ifelse(sex == 1, "Male", "Female"))
fit <- survfit(Surv(time, status) ~ sex, data = lung) 

hc <- hchart(fit, ranges = TRUE)
hc

Principal component analysis

hc <- hchart(princomp(USArrests, cor = TRUE))
hc

Distance matrix

mtcars2 <- mtcars[1:20, ]
x <- dist(mtcars2)
hc <- hchart(x)
hc

Correlation matrix

hc <- hchart(cor(mtcars))
hc



Version: Français

Highchart Interactive Time Series Data Visualization in R (Prev Lesson)
(Next Lesson) Highchart Graphical Parameters Modifications
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