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 is NULL, meaning no coloring.

  • alpha: This is an option to set transparency for larger datasets. By default, it is set to 1.

  • corMethod: This is a method passed as an argument to the cor function.

Example

library(GGally)
data(flea)
ggscatmat(flea, columns = 2:4, color="species", corMethod="pearson")

Explanation

  • Line 1: We import the GGally library to use the ggscatmat function.
  • Line 2: We import the predefined flea dataset from R.
  • Line 3: We use columns 2,3,4 of the flea matrix in our plot and the species argument will give color to each column’s datapoints.
Copyright ©2024 Educative, Inc. All rights reserved