| Title: | Sector-Adjusted Points Plot for Feature Dominance |
|---|---|
| Description: | Visualizes feature influence by projecting data into 2D via PCA and adjusting points toward sector centers weighted by importances. Supports linear models and optionally tree-based models via SHAP values from the 'fastshap' package. For tree-based models, please install 'fastshap' manually from the CRAN archive: <https://cran.r-project.org/src/contrib/Archive/fastshap/>. |
| Authors: | Mohamed Amine FARES [aut, cre] |
| Maintainer: | Mohamed Amine FARES <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.16 |
| Built: | 2026-09-14 11:46:20 UTC |
| Source: | https://github.com/cran/sappviz |
Adjust PCA coordinates toward sector centers
adjust_points(coords, centers, influence, alpha = 0.6)adjust_points(coords, centers, influence, alpha = 0.6)
coords |
A matrix or data.frame with columns |
centers |
Matrix of sector centers (from |
influence |
A factor or integer vector of length nrow(coords), indicating the sector index/name for each point. |
alpha |
Blending parameter in [0,1]. 0 = no adjustment, 1 = full pull. |
A matrix of adjusted coordinates.
coords <- matrix(c(0.5, -0.3, -0.1, 0.8), ncol = 2) centers <- matrix(c(1, 0, -1, 0), ncol = 2, byrow = TRUE) rownames(centers) <- c("A", "B") influence <- c("A", "B") adjust_points(coords, centers, influence, alpha = 0.6)coords <- matrix(c(0.5, -0.3, -0.1, 0.8), ncol = 2) centers <- matrix(c(1, 0, -1, 0), ncol = 2, byrow = TRUE) rownames(centers) <- c("A", "B") influence <- c("A", "B") adjust_points(coords, centers, influence, alpha = 0.6)
Compute the most influential feature per observation (Model-Agnostic)
influence_feature(data, model, scale_data = TRUE)influence_feature(data, model, scale_data = TRUE)
data |
Data frame of features. |
model |
A fitted model ( |
scale_data |
Boolean. If TRUE, scales data for lm to match PCA (default: TRUE). |
A character vector of feature names (most influential per row).
data(iris) X <- iris[, 1:4] model <- lm(Petal.Width ~ Sepal.Length + Sepal.Width + Petal.Length, data = iris) influence_feature(X, model)data(iris) X <- iris[, 1:4] model <- lm(Petal.Width ~ Sepal.Length + Sepal.Width + Petal.Length, data = iris) influence_feature(X, model)
SAPP: Professional Enhanced Visualization
plot_sapp(data, importances, influence, alpha = 0.6, scale_coords = TRUE, ...)plot_sapp(data, importances, influence, alpha = 0.6, scale_coords = TRUE, ...)
data |
Data frame of original features (numeric). |
importances |
Named numeric vector of feature importances. |
influence |
Vector of length nrow(data) indicating the MOST influential feature. |
alpha |
Adjustment strength. Numeric (0-1) OR "auto". |
scale_coords |
Whether to scale PCA coordinates to unit disk (default TRUE). |
... |
Additional arguments passed to |
A ggplot object.
library(sappviz) data(iris) X <- iris[, 1:4] model <- lm(Petal.Width ~ Sepal.Length + Sepal.Width + Petal.Length, data = iris) imp <- abs(coef(model)[-1]) names(imp) <- c("Sepal.Length", "Sepal.Width", "Petal.Length") inf <- influence_feature(X, model) plot_sapp(X, imp, inf, alpha = "auto")library(sappviz) data(iris) X <- iris[, 1:4] model <- lm(Petal.Width ~ Sepal.Length + Sepal.Width + Petal.Length, data = iris) imp <- abs(coef(model)[-1]) names(imp) <- c("Sepal.Length", "Sepal.Width", "Petal.Length") inf <- influence_feature(X, model) plot_sapp(X, imp, inf, alpha = "auto")
Compute sector centers based on feature importances
sector_centers(importances, radius = 1)sector_centers(importances, radius = 1)
importances |
A named numeric vector of feature importances (positive). |
radius |
Radius of the circle on which centers are placed (default 1). |
A matrix with columns x and y for each feature.
imp <- c(Sepal.Length = 0.4, Sepal.Width = 0.1, Petal.Length = 0.35, Petal.Width = 0.15) sector_centers(imp)imp <- c(Sepal.Length = 0.4, Sepal.Width = 0.1, Petal.Length = 0.35, Petal.Width = 0.15) sector_centers(imp)