Parallel coordinates plot is a data visualisation specially designed for visualising and analysing multivariate, numerical data. It is ideal for comparing multiple variables together and seeing the relationships between them. For example, the variables contribute to Happyness Index.
In this hands-on exercise, you will learn how to plot parallel coordinate programmatically using appropriate R packages.
For this exercise, the GGally, plotly R, parcoords and tidyverse packages will be used.
The code chunks below are used to install and load the packages in R.
packages = c('GGally', 'plotly', 'parcoords', 'tidyverse')
for(p in packages){
if(!require(p, character.only = T)){
install.packages(p)
}
}
In this hands-on exercise, the World Happines 2018 (http://worldhappiness.report/ed/2018/) data will be used. The data set is download at https://s3.amazonaws.com/happiness-report/2018/WHR2018Chapter2OnlineData.xls. The original data set is in Microsoft Excel format. It has been extracted and saved in csv file called WHData-2018.csv.
In this section, you will learn how to visualise and analyse multiple continous variables using correlation matrix, parallel coordinate plot and heatmap. World Happiness Report 2018 dataset (WHData-2018.csv) will be used in this section.
First, important the data into R by using the code below.
wh <- read_csv("data/WHData-2018.csv")
The code chunk below is used to plot a basic parallel coordinates by using ggparcoord() of GGally package.
ggparcoord(data = wh,
columns = c(7:12))
ggparcoord(data = wh,
columns = c(7:12),
groupColumn = 2,
scale = "uniminmax",
boxplot = TRUE,
title = "Parallel Coord. Plot of World Happines Attributes")
ggparcoord(data = wh,
columns = c(7:12),
groupColumn = 2,
scale = "uniminmax",
boxplot = TRUE,
title = "Parallel Coord. Plot of World Happines Attributes") +
facet_wrap(~ Region)
parcoords is a htmlwidget for d3 parallel coordinates plot. It gives R users the very well designed and interactive parallel-coordinates chart for d3 with the infrastructure, flexibility, and robustness of htmlwidgets.
parcoords(
wh[,7:12],
reorderable = T,
brushMode = '1D-axes')
parcoords(
wh[,7:12],
rownames = FALSE,
reorderable = T,
brushMode = '1D-axes')
[ggparcoord function] (http://ggobi.github.io/ggally/rd.html#ggparcoord) of GGally package