Can I visualize standardized CFA model loadings in R instead of estimated ones?

Hey everyone! I’m working with the lavaan package in R for confirmatory factor analysis. I’ve got my CFA model set up and running fine, but I’m stuck on the visualization part. I want to create a plot that shows the standardized loadings (the ‘Std.all’ column in lavaan output) rather than the estimated loadings. I’ve been using lavaanPlot, but I can’t figure out how to make it use the standardized values.

Here’s a quick example of what I’m doing:

library(lavaan)
library(lavaanPlot)

# Simple CFA model
model <- 'factor =~ item1 + item2 + item3'
fit <- cfa(model, data = mydata)

# This plot uses estimated loadings, not standardized
lavaanPlot(model = fit, coefs = TRUE)

I’ve tried messing with the ‘edge_options’ argument, but no luck. Does anyone know how to plot the standardized loadings instead? Or maybe there’s another package that might help? Any assistance would be greatly appreciated!

Hey Ava_Books! :wave: I totally get your struggle with visualizing those standardized loadings. Have you considered giving the ‘DiagrammeR’ package a shot? It’s pretty versatile and might be just what you’re looking for!

Here’s a quick idea of how you could use it:

library(DiagrammeR)
library(lavaan)

# After fitting your model
std_loadings <- standardizedSolution(fit)

# Create the graph
graph <- create_graph()
graph <- add_node(graph, label = 'Factor')
for (i in 1:3) {
  graph <- add_node(graph, label = paste0('Item', i))
  graph <- add_edge(graph, from = 'Factor', to = paste0('Item', i),
                    label = round(std_loadings$est.std[i], 2))
}

# Render the graph
render_graph(graph)

This should give you a neat diagram with your factor and items, showing the standardized loadings on the edges. You can tweak it to your heart’s content!

What do you think? Wanna give it a try? I’m super curious to hear if this works for you or if you’ve found another cool solution! :blush:

hey ava! have u tried using the semPlot package? it’s pretty neat for visualizing SEMs and CFAs. u can use the semPaths() function to plot standardized loadings. just set the ‘whatLabels’ argument to “std” like this:

semPaths(fit, whatLabels=“std”, edge.label.cex=0.8)

Hope this helps! lemme know if u need anything else :slight_smile:

I’ve encountered a similar issue before, and I found that the ‘semPlot’ package, as mentioned earlier, is indeed quite useful. However, another approach you might consider is using the ‘tidySEM’ package. It offers more flexibility in customizing your plots.

Here’s a basic example of how you could use it:

library(tidySEM)

graph_sem(fit) %>%
  edit_graph({
    edges$label <- standardizedSolution(fit)$est.std[match(edges$label, standardizedSolution(fit)$label)]
    edges
  }) %>%
  plot()

This method allows you to directly use the standardized estimates from your lavaan model. It’s a bit more code, but it gives you greater control over the final visualization. You can further customize the appearance by adding more arguments to the plot() function.