0
library(ggpmisc)
data <- mpg
table(data$class)
data$class[mpg$class=="2seater"] <- c(rep("2seater", 1), rep("compact", 4))
formula <- y ~ x + I(x^2)
ggplot(data, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  geom_smooth(method = "lm", formula = formula) +
  ggpmisc::stat_poly_eq(aes(label =  paste(stat(eq.label), stat(adj.rr.label), sep = "*\", \"*")),
               formula = formula, parse = TRUE) 

The above code will produce a plot without the formula and r-squared labels. And will give this warning:

Warning message:
Computation failed in `stat_poly_eq()`:
argument "x" is missing, with no default 

The problem stems from the fact that the 2seater color group only has one data point. It isn't enough. But then it should at least output labels for the other groups?

  • 1
    Thanks! This is indeed a bug in `stat_poly_eq()`. Can you please raise an issue at https://github.com/aphalo/ggpmisc/issues ? You can just copy this question. – Pedro J. Aphalo May 23 '21 at 01:27

1 Answers1

1

The problem is now fixed in upcoming 'ggpmisc' (0.4.0), which can be installed from GitHub. At the moment the fixed version can be installed with remotes::install_github("aphalo/ggpp") followed by remotes::install_github("aphalo/ggpmisc").

Once both packages are in CRAN updating 'ggpmisc' will be enough.

Pedro J. Aphalo
  • 5,796
  • 1
  • 22
  • 23