Summary
This chart is done for a self-training purpose. In order to create chord diagram, we will use the Circlize package from Zuguang Gu. Great tutorial to start: How to make Chord Diagram by Zuguang Gu
The data source I use is the “Erasmus student mobility: home and destination countries” related to the academic year 2012-2013.
Data source (pdf) from ec.europea.eu
The dataset “shows the total number of Erasmus students sent abroad from the home country (vertical axis) to the destination country (horizontal axis)”
library(circlize)
library(dplyr)
library(countrycode)`160929_erasmus.2012.2013` <- read.csv("C:/Users/marc/Desktop/Data/160929_erasmus/160929_erasmus 2012-2013.csv", sep=";", stringsAsFactors=FALSE)
data.source <- `160929_erasmus.2012.2013`
rownames(data.source) <- data.source$X
head(data.source[1:10,2:10]) #how the dataset looks like## BE BG CZ DK DE EE GR ES FR
## BE 0 20 125 236 592 17 33 1527 1155
## BG 87 0 107 30 360 20 81 180 191
## CZ 314 37 0 190 1145 60 102 702 720
## DK 75 38 42 0 567 23 22 414 363
## DE 622 51 508 936 0 214 167 6373 5450
## EE 26 7 40 39 151 0 15 135 77
Erasmus student mobility: home and destination countries within Western Europe
western.eu <- select(data.source, -X, -MK) #MK is not needed
colnames(western.eu) <- countrycode(colnames(western.eu), origin = "iso2c", destination = "country.name")
colnames(western.eu)[27] <- "United Kingdom" #should have been GBR!
rownames(western.eu) <- colnames(western.eu)
west.index <- countrycode(colnames(western.eu), origin = "country.name", destination= "region") == "Western Europe"
western.eu <- western.eu[west.index,west.index]
western.eu <- as.matrix(western.eu)
col.west <- c("#003366", "#ffa500", "#b4eeb4", "#fff68f", "#40e0d0", "#ff7f50", "#00ff7f", "#daa520")
chordDiagram(western.eu,transparency = 0.2,
grid.col= col.west,
grid.border= "grey",
directional= 2,
link.largest.ontop = TRUE,
annotationTrack= c("name","grid","axis"),
link.lwd = 1.5,
link.border = "grey")circos.clear()Erasmus student mobility: home and destination countries for flux higher than 2000
europe <- select(data.source, -X)
colnames(europe) <- countrycode(colnames(europe), origin = "iso2c", destination = "country.name")
colnames(europe)[27] <- "United Kingdom"
rownames(europe) <- colnames(europe)[1:33]
reduce <- europe < 2000
europe[reduce] <- 0
europe <- as.matrix(europe)
color.europe <- rand_color(34, transparency = 0.2)
circos.par(gap.degree = 3,#can be vector
start.degree = 90,
track.margin = c(0.05,0.05))#gap btw center axis and labels
chordDiagram(europe,
grid.col= color.europe,
grid.border= "grey",
directional= 2,
link.largest.ontop = TRUE,
annotationTrack= c("name","grid","axis"),
link.lwd = 1.5,
link.border = "grey")circos.clear()