The Wayback Machine - https://web.archive.org/web/20240607152423/https://www.geeksforgeeks.org/parallel-coordinates-chart-with-ggally-in-r/
Open In App

Parallel coordinates chart with ggally in R

Last Updated : 24 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

To analyze and visualize high-dimensional data, one can use Parallel Coordinates. A background is drawn consisting of n parallel lines, often vertical and evenly spaced, to display a set of points in an n-dimensional space. A point in n-dimensional space is represented by a polyline with vertices on parallel axes; the ith coordinate of the point corresponds to the position of the vertex on the ith axis.

This representation is similar to time series visualization, except that it is used with data that does not have a natural order because the axes do not correlate to points in time. As a result, several axis layouts may be of interest.

Parallel coordinates chart with ggally in R Programming Language

In R programming Language, using the ggally packages, and the ggparcoord() function one can create the simplest basic parallel coordinates chart.

The input dataset must be a data frame containing multiple numeric variables, each of which will serve as a vertical axis on the chart. The function’s columns argument specifies the number of columns for these variables.

Plotting the Parallel Coordinate plot with IRIS Data

Here we are going to plot the parallel Coordinate plot with the iris dataset for this we will create dataframe from this dataset and then we will plot parallel Coordinate using ggparcoord() method.

Syntax: ggparcoord( data, columns, groupColumn)

Parameters:

  • data: Dataset to plot
  • columns: Vector of variables (either names or indices) to be axes in the plot
  • groupColumn: Single variable to group (color) by

R




# libraries
library(GGally)
 
# default data in R
data <- iris
 
# glimpse of the data
head(data)
 
# plotting the Parallel Coordinates
ggparcoord(data, # data
           columns = 1:3, # plotting first 3 columns
           groupColumn = 5) # target parameter


Output:

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

Customising Theme and Color

For customizing the theme and color within the plot we will use viridis and hrbrthemes package for color palette and themes for axis and plot.

R




# Libraries
library(GGally)
library(viridis)    # provide the color palette
library(hrbrthemes) # provides themes for axis and plot
 
# default data in R
data <- iris
 
# glimpse of the data
head(data)
 
# plotting the Parallel Coordinates
ggparcoord(data, # data
           columns = 1:3, # plotting first 3 columns
           alphaLines = .4, # transparency of the color
           groupColumn = 5, order = "anyClass",
           showPoints = TRUE) +
  theme(
    plot.title = element_text(size=10)
  )


Output:

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa



Similar Reads

Scaling Variables Parallel Coordinates chart in R
To analyse and visualise high-dimensional data, one can use Parallel Coordinates. A background is drawn consisting of n parallel lines, often vertical and evenly spaced, to display a set of points in an n-dimensional space. A point in n-dimensional space is represented by a polyline with vertices on parallel axes; the ith coordinate of the point co
4 min read
gGally Package in R
The gGally is an extension package to ggplot2 which contains functions to reduce the complexity of combining geoms. The plots like Scatterplot Matrix, Parallel Coordinates Plot, etc, While plotting the graphs using the ggplot() function we need to combine the geom() object to specify the type of plot but when it comes to the gGally package it conta
3 min read
Parallel processing using "parallel" in R
Parallel processing allows your application to do more tasks in less time. These assist in solving significant issues. In this article, we are going to look at how we can do parallel processing using the parallel library in R Programming Language. Using parallel library The parallel is a base package that was included in R 2.14.0. It expands on the
3 min read
Parallel chart with the MASS library in R
To analyze and visualize high-dimensional data, one can use Parallel Coordinates. A background is drawn consisting of n parallel lines, often vertical and evenly spaced, to display a set of points in an n-dimensional space. A point in n-dimensional space is represented by a polyline with vertices on parallel axes; the ith coordinate of the point co
2 min read
Random Forest with Parallel Computing in R Programming
Random Forest in R Programming is basically a bagging technique. From the name we can clearly interpret that this algorithm basically creates the forest with a lot of trees. It is a supervised classification algorithm. In a general scenario, if we have a greater number of trees in a forest it gives the best aesthetic appeal to all and is counted as
4 min read
Compute the Parallel Minima and Maxima between Vectors in R Programming - pmin() and pmax() Functions
pmin() function in R Language is used to return the parallel minima of the input vectors. Syntax: pmin(x1, x2) Parameters: x1: vector one x2: vector two Example 1: # R program to illustrate # pmin() function # First example vector x1 &lt;- c(2, 9, 5, 7, 1, 8) # Second example vector x2 &lt;- c(0, 7, 2, 3, 9, 6) # Application of pmin() in R pmin(x1,
1 min read
Parallel Programming In R
Parallel programming is a type of programming that involves dividing a large computational task into smaller, more manageable tasks that can be executed simultaneously. This approach can significantly speed up the execution time of complex computations and is particularly useful for data-intensive applications in fields such as scientific computing
8 min read
foreach parallel computing using external packages
Parallel computing is a method of breaking down large computational tasks into smaller ones that can be executed simultaneously on multiple processors or cores, leading to faster results. The foreach loop is a popular construct in R programming, which allows users to iterate over a list or vector of elements. In parallel computing, foreach can be u
7 min read
TryCatch with parLapply (Parallel package) in R
R has a useful function called 'tryCatch' that enables you to handle errors and warnings that could happen while your code is being executed. When combined with the parallel package function 'parLapply', which parallelly applies a function to each member of a list, you can run many instances of your code at once and manage any problems or warnings
8 min read
R - Pareto Chart
A Pareto chart is a combination of a bar chart and a line chart used for visualization. In R Pareto charts, the right vertical axis is used for cumulative frequency while the left vertical axis represents frequency. They basically use the Pareto principle which says that 80% of effects are produced from 20% of causes of systems. Here, we have a bar
3 min read
Article Tags :