Combine fields into an edge label
Closed this issue · 13 comments
library(lavaan)
#> This is lavaan 0.6-7
#> lavaan is BETA software! Please report any bugs.
library(tidySEM)
fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars)
set.seed(4)
graph_sem(fit, label = "est_sig_std")
graph_sem(fit, label = "confint_std")
would be nice if this could be done:
graph_sem(fit, label = c("est_sig_std","confint_std"))
or even, this would allow for "est_sig"
to be:
graph_sem(fit, label = c("est","sig"))
Created on 2020-10-14 by the reprex package (v0.3.0)
I don't think this is within scope. The proposed interface introduces an implicit syntax, where label = c("est_sig_std","confint_std")
means that the columns are pasted together. It seems more fitting of the tidySEM interface to edit the nodes()
and edges()
objects directly, for complete freedom over how the labels are rendered.
By pasting together pieces into a label?
That does sound like a good idea -
but currently get_edges(fit)
only gives the processed label, not the other possible pieces, so it is not possible.
I'm working on a possible solution, what do you think would be an intuitive way to solve this?
What I'm doing now is allowing users to pass the arguments of table_results()
to get_edges()
, so that it is possible to request additional columns
. These can then be used in a label, e.g. with tidyr::unite()
That sounds like a great idea! Yes!
I've also implemented support for expressions in the label argument, as you requested. This needs to be tested before it can go to CRAN, though, as it involves a major rewrite of several functions.
I would be happy to test this out in the morning, if you can point me in the right direction ..?
No, because not all rows in table_results()
are edges; some are means or thresholds etc.
I'm writing some help files for the new get_edges()
and get_nodes()
, to help you get started!
Alright - please install dev version 0.1.4
, it has new help files with examples. Could you check whether this does approximately what you wanted, and see whether they work in your code?
This is 🔥🔥🔥🔥🔥🔥
library(lavaan)
#> This is lavaan 0.6-7
#> lavaan is BETA software! Please report any bugs.
library(tidySEM)
#> Registered S3 methods overwritten by 'tidySEM':
#> method from
#> print.mplus.model MplusAutomation
#> print.mplusObject MplusAutomation
#> summary.mplus.model MplusAutomation
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
fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars)
lay <- get_layout(NA, NA, "am",
"mpg", NA, NA,
NA, NA, "cyl", rows = 3)
edg <- get_edges(fit, columns = c("est_std", "est_sig_std", "confint_std", "pval_std"), digits = 2) %>%
mutate(label = paste0(est_std, " ", confint_std),
color = "black",
color = replace(color, as.numeric(pval_std) < 0.05, "green"))
nod <- get_nodes(fit) %>%
mutate(color = "black",
color = replace(color, name=="mpg", "red"))
graph_data <- prepare_graph(model = fit, layout = lay, edges = edg, nodes = nod)
plot(graph_data)
Created on 2021-02-19 by the reprex package (v1.0.0)
Thank you for the suggestion and helping me debug @mattansb , version 0.1.6 is on CRAN now :)
My pleasure! Thanks for a pkg for easy pretty plots!