plt.2dcm: Create a ggplot Plot from a 2D Correlation Matrix

View source: R/plt.2dcm.R

plt.2dcmR Documentation

Create a ggplot Plot from a 2D Correlation Matrix

Description

This function creates a ggplot visualization from a 2D correlation matrix, such as those produced by cm.sr or cm.nsr. The function attempts to extract numeric wavelengths from the column names. If the extraction fails, sequential indices are used.

Usage

plt.2dcm(
  data,
  mapping = NULL,
  ...,
  show.stat = TRUE,
  environment = parent.frame()
)

Arguments

data

A numeric 2D matrix of correlation coefficients.

mapping

Optional ggplot2 aesthetic mapping.

...

Additional arguments passed to ggplot.

show.stat

Logical. If TRUE, prints the best R^2 value and corresponding bands.

environment

The environment in which to evaluate the plot. Defaults to parent.frame().

Details

It replaces the former ggplot.cm().

The function extracts numeric wavelengths from the column names of data. If these cannot be determined, sequential indices are used instead.

Value

A ggplot object visualizing the correlation matrix.

Examples

## Not run: 
  library(visa)
  data(NSpec.DF)
  x <- NSpec.DF$N  # nitrogen
  S <- NSpec.DF$spectra[, seq(1, ncol(NSpec.DF$spectra), 10)]  # resampled to 10 nm steps
  cm2d <- cm.sr(S, x, cm.plot = FALSE)
  p2d <- plt.2dcm(cm2d)
  print(p2d)

## End(Not run)


visa documentation built on April 4, 2025, 5:40 a.m.