1.0 Overview

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.

2.0 Installing and Launching 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)
  }
}

3.0 Data Preparation

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.

3.1 Importing World Happiness Data Set

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")

4.0 Working with ggparcoord() of GGally package

4.1 Plotting a simple parallel coordinates

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))

4.2 Plotting a parallel coordinates with boxplot

  • Underlay univariate boxplots, add title, use uniminmax scaling
ggparcoord(data = wh, 
           columns = c(7:12), 
           groupColumn = 2,
           scale = "uniminmax", 
           boxplot = TRUE, 
           title = "Parallel Coord. Plot of World Happines Attributes")

4.3 Parallel coordinates with facet

  • Underlay univariate boxplots, add title, use uniminmax scaling
ggparcoord(data = wh, 
           columns = c(7:12), 
           groupColumn = 2,
           scale = "uniminmax", 
           boxplot = TRUE, 
           title = "Parallel Coord. Plot of World Happines Attributes") +
  facet_wrap(~ Region)

5.0 Plotting Interactive Parallel Coordinates

5.1 Getting to know parcoords package

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.

5.2 Plotting an interactive parallel coordinates

parcoords(
 wh[,7:12],
 reorderable = T,
 brushMode = '1D-axes')
parcoords(
 wh[,7:12],
 rownames = FALSE,
 reorderable = T,
 brushMode = '1D-axes')