Interactive chord diagram with R

This post describes how to build an interactive chord diagram on which you can hover groups to highlight flows.

Chord section Data to Viz

The chorddiag package allows to build interactive chord diagrams with R. It expects a square matrix as input, providing flow strength between each pair of nodes that will be displayed around the circle.

Once the data formated properly, the chorddiag() function will automatically build the chart for you.

Note: The chorddiag package is a project by Mattflor and this example comes from its documentation.

# Load package
# devtools::install_github("mattflor/chorddiag")

# Create dummy data
m <- matrix(c(11975,  5871, 8916, 2868,
              1951, 10048, 2060, 6171,
              8010, 16145, 8090, 8045,
              1013,   990,  940, 6907),
            byrow = TRUE,
            nrow = 4, ncol = 4)

# A vector of 4 colors for 4 groups
haircolors <- c("black", "blonde", "brown", "red")
dimnames(m) <- list(have = haircolors,
                    prefer = haircolors)
groupColors <- c("#000000", "#FFDD89", "#957244", "#F26223")

# Build the chord diagram:
p <- chorddiag(m, groupColors = groupColors, groupnamePadding = 20)

# save the widget
# library(htmlwidgets)
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/chord_interactive.html"))

Related chart types

Chord diagram
Arc diagram
Edge bundling


This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting with

Github Twitter