plotdata: Advanced plot function

plotdataR Documentation

Advanced plot function

Description

Plot a dataset.

Usage

plotdata(
  d,
  k = NULL,
  target = NULL,
  type = c("pairs", "scatter", "parallel", "boxplot", "histogram", "barplot", "pie",
    "heatmap", "heatmapc", "correlation", "pca", "cda", "svd", "nmf", "tsne", "som",
    "words"),
  legendpos = "topleft",
  alpha = 200,
  asp = 1,
  labels = FALSE,
  tsne = NULL,
  nmf = NULL,
  ...
)

Arguments

d

A numeric dataset (data.frame or matrix).

k

The variable the observations are told apart by: they are coloured, grouped or, for type = "cda", discriminated by it. It is categorical, and cluster numbers do just as well as a factor. Left NULL, it is taken from d when exactly one of its columns is qualitative, or from target when that one is categorical.

target

The variable to be explained, read by type = "correlation" only. Unlike k it may be continuous. Give one or the other, the way cutree takes either k or h: a categorical target also serves as k, and k serves as target when none is given. A continuous target leaves the observations uncoloured, having no groups to offer.

type

The type of graphic to be plotted. See the Details section on the projections.

legendpos

Position of the legend

alpha

Opacity of the plotted points, from 0 (invisible) to 255 (opaque). Useful on dense scatter plots, where points would otherwise hide each other. The legend stays opaque.

asp

Aspect ratio: 1 (the default) makes one unit as long on both axes, NA lets them scale independently.

labels

Indicates whether or not labels (row names) should be showned on the (scatter) plot.

tsne

A precomputed TSNE result. When type = "tsne", providing this avoids recomputing the (randomized, potentially costly) t-SNE embedding on every call; if NULL (default), it is computed internally as before.

nmf

A precomputed NMF result. When type = "nmf", providing this avoids recomputing the (randomized, potentially costly) NMF decomposition on every call; if NULL (default), it is computed internally as before.

...

Other parameters.

Details

type = "correlation" draws how strongly each variable relates to the target, sorted, strongest at the top. Two different quantities, depending on the target. Against a numeric target it is Pearson's correlation r, sign included, and the axis says so. Against a categorical one it is the correlation ratio \eta, the square root of the between-class share of the variance – not a Pearson coefficient computed on class numbers, which would depend on the order the classes happen to be in and would mean nothing beyond two classes. \eta lies in [0, 1], is defined for any number of classes and does not depend on their coding. On exactly two classes \eta is |r| with the classes coded 0/1, so the sign comes back and says which class the variable is larger in.

The projections (type = "pca", and the default "scatter"/"pairs" on more than two variables) are computed on the data as they are, unscaled – plotdata shows a dataset, whereas PCA performs a factorial analysis and centres and scales by default. So plotdata (d, type = "pca") and plot (PCA (d)) differ visibly when the variables have very different scales, and PCA is the one to use for a properly scaled projection.

Examples

require (datasets)
data (iris)
# Without classification
plotdata (iris [, -5]) # Default (pairs)
# With classification
plotdata (iris [, -5], iris [, 5]) # Default (pairs)
plotdata (iris, 5) # Column number
plotdata (iris) # Automatic detection of the classification (if only one factor column)
plotdata (iris, type = "scatter") # Scatter plot (PCA axis)
plotdata (iris, type = "parallel") # Parallel coordinates
plotdata (iris, type = "boxplot") # Boxplot
plotdata (iris, type = "histogram") # Histograms
plotdata (iris, type = "heatmap") # Heatmap
plotdata (iris, type = "heatmapc") # Heatmap (and hierarchalcal clustering)
plotdata (iris, type = "pca") # Scatter plot (PCA axis)
plotdata (iris, type = "cda") # Scatter plot (CDA axis)
plotdata (iris, type = "svd") # Scatter plot (SVD axis)
plotdata (iris, type = "som") # Kohonen map
# With only one variable
plotdata (iris [, 1], iris [, 5]) # Default (data vs. index)
plotdata (iris [, 1], iris [, 5], type = "scatter") # Scatter plot (data vs. index)
plotdata (iris [, 1], iris [, 5], type = "boxplot") # Boxplot
# With two variables
plotdata (iris [, 3:4], iris [, 5]) # Default (scatter plot)
plotdata (iris [, 3:4], iris [, 5], type = "scatter") # Scatter plot
data (titanic)
plotdata (titanic, type = "barplot") # Barplots
plotdata (titanic, type = "pie") # Pie charts
## Not run: 
# Reusing a previously computed t-SNE embedding instead of recomputing it
res = TSNE (iris [, -5])
plotdata (iris [, -5], iris [, 5], type = "tsne", tsne = res)

## End(Not run)

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.