jacob-long / jtools

Tools for summarizing/visualizing regressions and other helpful stuff
https://jtools.jacob-long.com
GNU General Public License v3.0
162 stars 22 forks source link

jtools plots do not work in R 4.2 #133

Closed biodavidjm closed 1 year ago

biodavidjm commented 1 year ago

Everything works fine in R 4.1.3. However, the many jtools functions that generate plots fail in R > 4.2 (at least in R 4.2.2, which is the one that I am currently using)

For example, when trying to run just the example available in effect_plot

# Using a fitted lm model
states <- as.data.frame(state.x77)
states$HSGrad <- states$`HS Grad`
fit <- lm(Income ~ HSGrad + Murder,
  data = states)
effect_plot(model = fit, pred = Murder)
fit <- lm(accel ~ poly(mag,3) + dist, data = attenu)

effect_plot(fit, pred = mag, interval = TRUE,
  int.type = "confidence", int.width = .8, data = attenu)

it fails and generates the following error:

Error in element_line(colour = text_and_line_color, linewidth = 0.5, linetype = 1,  : 
  unused argument (linewidth = 0.5)
In addition: Warning message:
Ignoring unknown parameters: linewidth 

And the same is true for plot_summs

states <- as.data.frame(state.x77)
fit1 <- lm(Income ~ Frost + Illiteracy + Murder +
           Population + Area + `Life Exp` + `HS Grad`,
           data = states, weights = runif(50, 0.1, 3))
fit2 <- lm(Income ~ Frost + Illiteracy + Murder +
           Population + Area + `Life Exp` + `HS Grad`,
           data = states, weights = runif(50, 0.1, 3))
fit3 <- lm(Income ~ Frost + Illiteracy + Murder +
           Population + Area + `Life Exp` + `HS Grad`,
           data = states, weights = runif(50, 0.1, 3))

# Plot all 3 regressions with custom predictor labels,
# standardized coefficients, and robust standard errors
plot_summs(fit1, fit2, fit3,
           coefs = c("Frost Days" = "Frost", "% Illiterate" = "Illiteracy",
                     "Murder Rate" = "Murder"),
           scale = TRUE, robust = TRUE)

# THE ERROR:

Loading required namespace: broom.mixed
Failed with error:  ‘there is no package called ‘broom.mixed’’
Loading required namespace: broom.mixed
Failed with error:  ‘there is no package called ‘broom.mixed’’
Loading required namespace: broom.mixed
Failed with error:  ‘there is no package called ‘broom.mixed’’
Error in element_line(colour = text_and_line_color, linewidth = 0.5, linetype = 1,  : 
  unused argument (linewidth = 0.5)
In addition: Warning messages:
1: Ignoring unknown parameters: linewidth 
2: Ignoring unknown parameters: linewidth 

In this case, broom.mixed is not even available yet for R 4.2.2

Does everything work on your side?

And thank you very much for this magnificent package!

jacob-long commented 1 year ago

Hi @biodavidjm, I'm not sure about why broom isn't compatible with R 4.2.2, but the issue with the plotting should be able to be remedied by updating ggplot2 to its latest version. The latest update of jtools had to make changes to be compatible with the newer ggplot2, but I did not make users update ggplot2 at the same time.

biodavidjm commented 1 year ago

Indeed that solved the problem. Thanks!