Skip to content

plot_predictions and labs dictionary #1628

@brueckmann

Description

@brueckmann

Hello,
great package, love it!
Just a minor something I realized:

I cannot add labs via dictionary to plot_predictions. Please see the minimal reproducible example below.

library("marginaleffects")
library("ggplot2")

# Set labels by variable name instead of aesthetic from https://ggplot2.tidyverse.org/reference/labs.html?q=labs#null
cardict  <-  c(
  disp = "Displacment",
  # Not in use
  cyl  = "Number of cylinders",
  mpg  = "Miles per gallon",
  wt   = "Weight (1000 lbs)"
)

# Works in ggplot
ggplot(mtcars, aes(mpg, hp, colour = wt)) + geom_point() +
  labs(dictionary = cardict) +
  theme_classic() # just to see that it did sth.


mod <- lm(mpg ~ hp + wt, data = mtcars)

# and plot_prediction it - labels don't show
plot_predictions(mod, condition = "wt") +
  labs(dictionary = cardict) +
  theme_classic() # just to see that it did sth.

  1. sessionInfo() output
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS 15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_4.0.0          marginaleffects_0.31.0

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5        cli_3.6.5          rlang_1.1.6        generics_0.1.4     ellmer_0.3.2       S7_0.2.0          
 [7] coro_1.1.0         jsonlite_2.0.0     data.table_1.17.99 labeling_0.4.3     glue_1.8.0         backports_1.5.0   
[13] scales_1.4.0       rappdirs_0.3.3     grid_4.4.0         tibble_3.3.0       lifecycle_1.0.4    httr2_1.2.1       
[19] insight_1.4.2.13   compiler_4.4.0     dplyr_1.1.4        RColorBrewer_1.1-3 pkgconfig_2.0.3    rstudioapi_0.17.1 
[25] farver_2.1.2       R6_2.6.1           tidyselect_1.2.1   pillar_1.11.0      curl_7.0.0         magrittr_2.0.4    
[31] checkmate_2.3.2    withr_3.0.2        tools_4.4.0        gtable_0.3.6      

Hope that helps!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions