Learn R Programming

visa (version 1.0.0)

plt.2dcm: 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()
)

Value

A ggplot object visualizing the correlation matrix.

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.

Examples

Run this code
if (FALSE) {
  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)
}

Run the code above in your browser using DataLab