Skip to content

Wrong legend title in simpleSlopePlot for mod #6

@ClaudiuPapasteri

Description

@ClaudiuPapasteri

I don't know if this package is still actively maintained. If it isn't, it would be such a pity because it is such an easy to use and straight to the point way to do simple meditation/moderation. Just wanted to say that the legend title (in this case should have been mod variable name) is not displayed in the ggplot2 graph constructed when setting simpleSlopePlot = TRUE, but is always printed as "name".

Surely the problem lies in this part of .simpleSlopePlot function:

  ggplot2::geom_abline(data=image$state$coef, ggplot2::aes(slope=slope, intercept=intercept, color=name), size=1.2) +
  ggplot2::labs(x=self$options$pred, y=self$options$dep) +
  ggplot2::scale_color_discrete(name = mod) +

I am not sure, R6 always trips me up. Here is a reprex suing the example in the docs:

set.seed(1234)
X <- rnorm(100)
M <- rnorm(100)
X_M <- X*M
Y <- 0.7*X + 0.1*M + 4.2*X_M + rnorm(100)
dat <- data.frame(X=X, M=M, Y=Y)   

medmod::mod(dat, dep = "Y", pred = "X", mod = "M", simpleSlopePlot = TRUE)
#> Loading required namespace: jmvcore
#> 
#>  MODERATION
#> 
#>  Moderation Estimates                                           
#>  ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ 
#>           Estimate      SE            Z            p            
#>  ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ 
#>    X       0.9511366    0.09649136     9.857221    < .0000001   
#>    M      -0.4706588    0.09227843    -5.100421     0.0000003   
#>    X:M     4.1853782    0.10085978    41.496998    < .0000001   
#>  ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
#> Loading required namespace: ggplot2

Created on 2023-04-05 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions