ibecav / CGPfunctions

Powell Miscellaneous Functions for Teaching and Learning Statistics
Other
25 stars 11 forks source link

Code breaking with upcoming ggplot2 3.3.1 release #24

Closed clauswilke closed 4 years ago

clauswilke commented 4 years ago

Hello,

this is a heads up that your code is breaking with the upcoming ggplot2 3.3.1 release (https://github.com/tidyverse/ggplot2/issues/3871#issuecomment-633419085). This is due to changes in stat_function() that now make it more sensitive to certain bad programming patterns, such as feeding in data via the aes() function.

The code at issue is code such as the following: https://github.com/ibecav/CGPfunctions/blob/62efdb6bff0aefb598c59bfbdda86052add5e1c0/R/seedist.R#L262-L271

You can generally fix the issue by feeding in the data via the data argument rather than via aes():

library(ggplot2)
x <- rnorm(100)

# bad
ggplot() +
  aes(x) +
  geom_density(color = "blue") +
  stat_function(fun = dnorm)
#> Error: Aesthetics must be either length 1 or the same as the data (1): x

# good
ggplot(data.frame(x)) +
  aes(x) +
  geom_density(color = "blue") +
  stat_function(fun = dnorm)

Created on 2020-05-25 by the reprex package (v0.3.0)

If you encounter any problems fixing these issues, I'm happy to help.

ibecav commented 4 years ago

Change made, submitted to CRAN and apparently accepted. Thank you again for the heads-up.