cjvanlissa / tidySEM

54 stars 7 forks source link

linetype doe not accept ggplot acceptable types? #25

Closed mattansb closed 3 years ago

mattansb commented 3 years ago
edges(g) <- edges(g) %>% 
  linetype_nonsig("dashed")

plot(g)
#> Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow) : 
#>   invalid line type: must be length 2, 4, 6 or 8
cjvanlissa commented 3 years ago

This works fine for me (note that the suggested syntax is below):

fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)
g <- prepare_graph(fit)
edges(g) <- edges(g) %>% 
  linetype_sig("dashed")

plot(g)

image

Suggested syntax:

prepare_graph(fit) %>%
  linetype_sig_edges("dashed") %>%
  plot()
mattansb commented 3 years ago

It's because all the edges are sig in your example:

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(magrittr)

fit <- sem("mpg ~ cyl\nmpg ~ am", data = mtcars, meanstructure = TRUE)

g <- prepare_graph(fit)

edges(g) <- edges(g) %>% 
  linetype_cov("dashed")

plot(g)
#> Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow): invalid line type: must be length 2, 4, 6 or 8

Created on 2021-03-08 by the reprex package (v1.0.0)

cjvanlissa commented 3 years ago

Pretty poor design choice on the side of ggplot to accept both numeric or character linetypes, but then to strictly enforce the type...