princomp,GRaster-method | R Documentation |
This function applies a principal component analysis to layers of a GRaster
.
## S4 method for signature 'GRaster'
princomp(x, scale = TRUE, scores = FALSE)
x |
A |
scale |
Logical: If |
scores |
Logical: If |
A multi-layer GRaster
with one layer per principal component axis. The pcs()
function can be used on the output raster to retrieve a prcomp
object from the raster, which includes rotations (loadings) and proportions of variance explained.
terra::princomp()
, terra::prcomp()
if (grassStarted()) {
# Setup
library(terra)
# Climate raster:
madChelsa <- fastData("madChelsa")
# Convert a SpatRaster to a GRaster:
chelsa <- fast(madChelsa)
# Generate raster with layers representing principal component predictions:
pcRast <- princomp(chelsa, scale = TRUE)
plot(pcRast)
# Get information on the PCA:
prinComp <- pcs(pcRast)
prinComp
summary(prinComp)
plot(prinComp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.