plot.locOuts: Diagnostic Plots for Local Outlier Detection ('locOuts')

View source: R/locOuts.R

plot.locOutsR Documentation

Diagnostic Plots for Local Outlier Detection ('locOuts')

Description

Produces diagnostic plots for local outlier detection results returned by locOuts. Available visualizations include a histogram of next distances, spatial distribution of next distances, and a parallel coordinate plot (PCP) for a selected observation and their neighborhood.

Usage

## S3 method for class 'locOuts'
plot(
  x,
  type = c("hist", "spatial", "pcp"),
  scale = c("none", "minmax", "zscore"),
  bins = 30,
  observation = 1,
  ...
)

Arguments

x

An object of class "locOuts" obtained from locOuts.

type

A character vector indicating which plots to generate. Options are:

"hist"

Histogram of next distances with cutoff visualized.

"spatial"

Spatial distribution of observations, colored by relative next distance.

"pcp"

Parallel coordinate plot for an observation and its neighbors.

scale

Character indicating how variables are scaled in the parallel coordinate plot. One of:

"none"

Use raw values (no scaling).

"minmax"

Min-max scaling to [0, 1].

"zscore"

Standardization: mean 0, standard deviation 1.

bins

Integer, number of histogram bins (default = 30).

observation

Integer or character; index or name of a specific observation to analyze in the PCP plot. Used only when type includes "pcp".

...

Additional parameters passed to low-level plotting functions (currently unused in ggplot versions).

Details

The function visualizes outlier behavior in different ways:

  • Histogram: Shows the distribution of next distances across observations. The cutoff is shown as a dashed line.

  • Spatial Plot: 2D plot of observation coordinates. Color encodes the ratio of next distance to cutoff.

  • Parallel Coordinate Plot (PCP): Shows scaled values across all variables for a selected observation (in red) and its neighbors (in blue or grey). The type of scaling can be controlled via the scale parameter.

Value

A named list with elements:

p_hist

ggplot object of the histogram (or NULL if not requested).

p_spatial

ggplot object of the spatial plot (or NULL).

p_pcp

ggplot object of the parallel coordinate plot (or NULL).

See Also

locOuts

Examples

set.seed(1)
data <- matrix(rnorm(2000), ncol = 4)
coords <- matrix(rnorm(1000), ncol = 2)
groups <- sample(1:10, 500, replace = TRUE)
outs <- locOuts(data = data,
                coords = coords,
                groups = groups,
                lambda = 0.3,
                k = 10)

# Generate all plots
plots <- plot(outs,
              type = c("hist", "spatial", "pcp"),
              observation = outs$outliers[1],
              scale = "minmax")
plots$p_hist
plots$p_spatial
plots$p_pcp

ssMRCD documentation built on Nov. 5, 2025, 7:44 p.m.