Parallel chart with the MASS library in R
Last Updated :
22 Feb, 2022
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 with MASS Library
The parcoord() function in the MASS package creates a parallel coordinates chart automatically. A data frame with solely numeric variables can be used as the input dataset. Each variable will be utilized to construct one of the chart’s vertical axes.
R
library (MASS)
data <- iris
head (data)
parcoord (iris[, c (1:4)] ,
col = colors ()[ as.numeric (iris$Species)*8]
)
|
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
Customizing the Color Palette
Basically, there are not any built-in methods or attributes in this package for color customization. We will use colorRampPalette() methods color range between two colors specified points
R
library (MASS)
library (RColorBrewer)
data <- iris
head (data)
palette <- brewer.pal (5, "Set1" )
parcoord (iris[, c (1:4)] ,
col = palette[ as.numeric (iris$Species)]
)
|
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...