coeff_plot: Coefficient plot for a SEM

Description Usage Arguments Value Examples

View source: R/coeff_plot.r

Description

This function plots a classic coefficient plot for a structural equation model. More ggplot functions (e.g., theme, labs, etc.) can be passed to the resulting object.

Usage

1
2
3
4
5
6
7
8
coeff_plot(
  object,
  effect = NULL,
  labels = FALSE,
  regressions = FALSE,
  y_limits = NULL,
  y_intercept = 0
)

Arguments

object

An object of class lavaan created by using sem() from the package 'lavaan'.

effect

Vector of specific effects in the model (need to be labelled in the original model)

labels

A logical value specifying whether only effects with labels should be plotted

y_limits

Change the limits of the x-axis.

y_intercept

Defaults to a dashed vertical line at y = 0.

regression

A logical value specifying whether only regressions should be plotted

Value

A ggplot object that can be further customized using standard ggplot elements.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(lavaan)
model <- '
  # latent variables
  ind60 =~ x1 + x2 + x3
  dem60 =~ y1 + y2 + y3 + y4
  dem65 =~ y5 + y6 + y7 + y8
  
  # regressions
  dem60 ~ a*ind60
  dem65 ~ b*ind60 + c*dem60
  
  # residual covariances
  y1 ~~ y5
  y2 ~~ y4 + y6
  y3 ~~ y7
  y4 ~~ y8
  y6 ~~ y8
'
fit <- sem(model,
data = PoliticalDemocracy)

# Creating output table
coeff_plot(fit, regression = T, y_limits = c(-1,2.5)) + theme_minimal()

masurp/pmstats documentation built on Oct. 6, 2020, 9:24 p.m.