plot.adjmat: Plot Function for S3 Class "adjmat"

View source: R/plot.adjmat.R

plot.adjmatR Documentation

Plot Function for S3 Class "adjmat"

Description

Visualize an adjacency matrix as a heatmap. This function is shared by objects returned from prec_to_adj.

Usage

## S3 method for class 'adjmat'
plot(x, ...)

Arguments

x

An object inheriting from S3 class "adjmat", typically returned by prec_to_adj.

...

Additional arguments passed to ggplot.

Value

A heatmap of class ggplot showing the matrix entries. The plot title also reports matrix dimension and sparsity.

Examples

library(grasps)

## reproducibility for everything
set.seed(1234)

## block-structured precision matrix based on SBM
sim <- gen_prec_sbm(p = 30, K = 3,
                    within.prob = 0.25, between.prob = 0.05,
                    weight.dists = list("gamma", "unif"),
                    weight.paras = list(c(shape = 20, rate = 10),
                                        c(min = 0, max = 5)),
                    cond.target = 100)
## ground truth visualization
plot(sim)

## n-by-p data matrix
library(MASS)
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)

## precision matrix: adaptive lasso; BIC
prec <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")

## precision matrix visualization
plot(prec)

## performance
performance(hatOmega = prec$hatOmega, Omega = sim$Omega)

## adjacency matrix: diagonal = 0; raw partial correlations;
##                   no thresholding; weighted network
adj <- prec_to_adj(prec$hatOmega,
                   diag.zero = TRUE, absolute = FALSE,
                   threshold = NULL, weighted = TRUE)

## adjacency matrix visualization
plot(adj)

grasps documentation built on Sept. 13, 2026, 1:07 a.m.