What is the ggscatmat function in R?
Overview
In R, ggscatmat is a scatter plot used for multivariate numerical data. It’s a part of the GGally library. It creates scatter plots in the lower triangle, density line graphs in the diagonal, and correlations in the upper triangle.
Syntax
The default implementation of ggscatmat in R is as follows:
ggscatmat(data, columns = 1:ncol(data), color = NULL, alpha = 1,
corMethod = "pearson")
Parameters
-
data: This is the data matrix that will be used. It should contain a numeric data matrix. -
columns: This is an option to choose the columns from the data matrix. By default, it selects all the columns—1:ncol(data). -
color: This is an option to group the dataset by factor and color them differently. By default, the value isNULL, meaning no coloring. -
alpha: This is an option to set transparency for larger datasets. By default, it is set to1. -
corMethod: This is a method passed as an argument to thecorfunction.
Example
library(GGally)data(flea)ggscatmat(flea, columns = 2:4, color="species", corMethod="pearson")
Explanation
- Line 1: We import the
GGallylibrary to use theggscatmatfunction. - Line 2: We import the predefined
fleadataset from R. - Line 3: We use columns
2,3,4of thefleamatrix in our plot and thespeciesargument will give color to each column’s datapoints.
Free Resources