cjvanlissa / tidySEM

54 stars 7 forks source link

Feature request: `hide_label` or `hide_mean` functions #58

Open rempsyc opened 1 year ago

rempsyc commented 1 year ago

In the "SEM graphing conventions" vignette, in the Measurement model section, the following is mentioned:

We see that the model defines a latent variable y, with mean fixed to 0 [...]

I understand from this that the label values under the variable names are usually the variable means by default. I am being asked to remove this information from the tidySEM plot. I have looked for a hide_label or hide_mean function to hide the mean (but keep the variable name obviously) but have not found any. I was wondering if you think it would make any sense to add such a function.

Because currently, my workaround is not that pretty:

library(lavaan)
#> This is lavaan 0.6-12
#> lavaan is FREE software! Please report any bugs.
library(tidySEM)
#> Loading required package: OpenMx
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
df <- iris[ , c(1,3:4)]
names(df) <- paste0("y_", 1:3)
fit <- tidy_sem(df) |> 
  measurement() |> 
  estimate_lavaan()
#> Warning in lav_object_post_check(object): lavaan WARNING: some estimated ov
#> variances are negative
p <- prepare_graph(fit)
nodes(p) <- nodes(p) |> 
  mutate(label = gsub("\\n(.*)", "", label))
plot(p)

Created on 2022-09-05 by the reprex package (v2.0.1)

We could use instead e.g.,

fit %>% 
  prepare_graph() |> 
  hide_label |> 
  plot()

Just an idea. Thanks!