| plot.locOuts | R Documentation |
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.
## S3 method for class 'locOuts'
plot(
x,
type = c("hist", "spatial", "pcp"),
scale = c("none", "minmax", "zscore"),
bins = 30,
observation = 1,
...
)
x |
An object of class |
type |
A character vector indicating which plots to generate. Options are:
|
scale |
Character indicating how variables are scaled in the parallel coordinate plot. One of:
|
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 |
... |
Additional parameters passed to low-level plotting functions (currently unused in ggplot versions). |
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.
A named list with elements:
p_histggplot object of the histogram (or NULL if not requested).
p_spatialggplot object of the spatial plot (or NULL).
p_pcpggplot object of the parallel coordinate plot (or NULL).
locOuts
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.