dendIMG: Draw dendrogram with images

Description Usage Arguments Details Examples

View source: R/dendIMG.R

Description

This is a customized dendrogram plot where images are added to the leaf labels. The function uses functions from the dendextend and stats libraries.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dendIMG(
  centers,
  img.list,
  type = c("mean0", "original", "correlation"),
  scale.same = FALSE,
  pal = colorRamps::matlab.like(100),
  lab.extra = c("none", "mean", "var"),
  color.labels = FALSE,
  color.breaks = c(-2, -0.4, 0.4, 2)
)

Arguments

centers

The centers. Each row is a center and each column is a variable.

img.list

A list of images for each center. Image 1 goes with center row 1, etc.

type

The type of distance to use. This will determine how to calculate the distance between the centers. See details.

scale.same

All images should be on the same scale

pal

The color ramp for the images. This will determine what the images look like.

lab.extra

Extra information to add to the labels. "mean" will add the mean value of the center (minus mean over all centers) and "var" will add the variance.

color.labels

If TRUE, the labels are blue if below a threshold, black within, and red over.

color.breaks

The breaks to use for the color labels.

Details

The dendrogram needs the distance between centers and there are many ways to measure this. The default is type="mean" to use the euclidian distance stats::dist(centers). "mean0" is similar but the mean of each center is removed (not the mean across centers, the mean of individual centers). If "correlation", then a correlation matrix is used as a distance matrix.

Once the distance matrix is calculated, stats::hclust() is used to create the cluster and stats::as.dendrogram() is used to create the dendrogram object from that. The images are added below the dendrogram plot using rasterImage().

A dendrogram object is returned.

Examples

1
2
3
4
centers <- matrix(runif(10*4), 10, 4)
img.list <- list()
for(i in 1:10) img.list[[i]] <- raster::as.raster(matrix(centers[i,],2,2))
dendIMG(centers, img.list, lab.extra="none")

UW-Upwelling-Project/imageryML documentation built on Dec. 18, 2021, 6:11 p.m.