Package {sappviz}


Title: Sector-Adjusted Points Plot for Feature Dominance
Version: 1.0.16
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/.
License: MIT + file LICENSE
URL: <https://github.com/FaresAminu/sappviz>
BugReports: https://github.com/FaresAminu/sappviz/issues
Imports: ggplot2 (≥ 3.4.0), ggrepel (≥ 0.9.0), stats
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown, randomForest, MASS, fastshap
Encoding: UTF-8
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-07-28 10:53:22 UTC; Click Computers
Author: Mohamed Amine FARES [aut, cre]
Maintainer: Mohamed Amine FARES <fares.mohamedamin@esas-eloued.dz>
Repository: CRAN
Date/Publication: 2026-08-06 12:50:02 UTC

Adjust PCA coordinates toward sector centers

Description

Adjust PCA coordinates toward sector centers

Usage

adjust_points(coords, centers, influence, alpha = 0.6)

Arguments

coords

A matrix or data.frame with columns x, y (PCA scores).

centers

Matrix of sector centers (from sector_centers).

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.

Value

A matrix of adjusted coordinates.

Examples

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)

Description

Compute the most influential feature per observation (Model-Agnostic)

Usage

influence_feature(data, model, scale_data = TRUE)

Arguments

data

Data frame of features.

model

A fitted model (lm, glm, randomForest, ranger).

scale_data

Boolean. If TRUE, scales data for lm to match PCA (default: TRUE).

Value

A character vector of feature names (most influential per row).

Examples


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

Description

SAPP: Professional Enhanced Visualization

Usage

plot_sapp(data, importances, influence, alpha = 0.6, scale_coords = TRUE, ...)

Arguments

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 ggplot2::geom_point.

Value

A ggplot object.

Examples


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

Description

Compute sector centers based on feature importances

Usage

sector_centers(importances, radius = 1)

Arguments

importances

A named numeric vector of feature importances (positive).

radius

Radius of the circle on which centers are placed (default 1).

Value

A matrix with columns x and y for each feature.

Examples

imp <- c(Sepal.Length = 0.4, Sepal.Width = 0.1, Petal.Length = 0.35, Petal.Width = 0.15)
sector_centers(imp)

mirror server hosted at Truenetwork, Russian Federation.