What Is Related To What In My Data?

stats
dataviz
R
Author

Andy Grogan-Kaylor

Published

June 3, 2026

In some recent projects, I have had to get a quick idea of what scales and demographic variables in my data are related to other scales and demographic variables.

It seems to me that one of the quickest ways to do this is with the corrgram (Wright, 2021) library. I also like pairs.panels in the psych (Revelle, 2025) library, and ggpairs in the GGally (Schloerke et al., 2025) library.

Lastly, a network graph using igraph (Csardi et al., 2025; Csardi & Nepusz, 2006) requires substantially more programming, and produces a quite different looking visualization that may or may not be useful in some situations.

Call Libraries

Show the code
library(MASS) # simulate multivariate data

library(pander) # nice tables

library(corrgram) # corrgrams

library(GGally) # pairs plots

library(psych) # useful routines for psych data

library(igraph) # network analysis

Simulated Data

I simulate some data.

TipKey Idea

Of particular note are that the strongest correlation is between scaleA and scaleB, and that scaleA and scaleC are negatively correlated.

Show the code
set.seed(54321)

# simulate data

mu <- c(scaleA = 10, scaleB = 25, scaleC = 100) # means

Sigma <- matrix(c(1.0, 0.75, -0.3, # variance covariance
                  0.75, 1.0, 0.4,
                  -0.3, 0.4, 1.0), 
                nrow = 3, ncol = 3)

mydata <- mvrnorm(n = 500, 
                  mu = mu, 
                  Sigma = Sigma) # variance covariance
Show the code
pander(head(mydata)) # nicely formatted table
scaleA scaleB scaleC
9.291 25.14 101.2
8.853 24.3 100.4
9.186 24.35 99.86
7.81 23.8 101.4
9.734 24.54 99.8
8.603 24.16 100.9
Show the code
skimr::skim(mydata) # descriptive statistics

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
scaleA 0 1 10.00 1.04 7.14 9.30 9.97 10.68 13.30 ▁▅▇▃▁
scaleB 0 1 24.94 1.00 22.12 24.27 24.92 25.62 27.97 ▁▅▇▅▁
scaleC 0 1 99.91 1.00 97.20 99.25 99.92 100.56 102.82 ▁▅▇▃▁

References

Csardi, G., & Nepusz, T. (2006). The igraph software package for complex network research. InterJournal, Complex Systems, 1695. https://igraph.org
Csardi, G., Nepusz, T., Traag, V., Horvat, S., Zanini, F., Noom, D., & Müller, K. (2025). igraph: Network analysis and visualization in R. https://doi.org/10.5281/zenodo.7682609
Revelle, W. (2025). Psych: Procedures for psychological, psychometric, and personality research. Northwestern University. https://CRAN.R-project.org/package=psych
Schloerke, B., Cook, D., Larmarange, J., Briatte, F., Marbach, M., Thoen, E., Elberg, A., & Crowley, J. (2025). GGally: Extension to ’ggplot2’. https://doi.org/10.32614/CRAN.package.GGally
Wright, K. (2021). Corrgram: Plot a correlogram. https://doi.org/10.32614/CRAN.package.corrgram