aphalo / ggpmisc

R package ggpmisc is an extension to ggplot2 and the Grammar of Graphics
https://docs.r4photobiology.info/ggpmisc
97 stars 6 forks source link

stat_poly_eq fails with errors #16

Closed lewishooper closed 3 years ago

lewishooper commented 3 years ago

stat_poly-eq fails with following message: Warning messages: 1: In as.character.polynomial(polynom::as.polynomial(coefs), digits = coef.digits, : NAs introduced by coercion 2: Computation failed in stat_poly_eq(): missing value where TRUE/FALSE needed For testing purposes I used the following repex from Stack overflow https://stackoverflow.com/questions/7549694/add-regression-line-equation-and-r2-on-graph/35140066#35140066

library(ggplot2) library(ggpmisc) df <- data.frame(x = c(1:100)) df$y <- 2 + 3 * df$x + rnorm(100, sd = 40) my.formula <- y ~ x p <- ggplot(data = df, aes(x = x, y = y)) +

  • geom_smooth(method = "lm", se=FALSE, color="black", formula = my.formula) +
  • ggpmisc::stat_poly_eq(formula = my.formula,
  • aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
  • parse = TRUE) +
  • geom_point() p Warning messages: 1: In as.character.polynomial(polynom::as.polynomial(coefs), digits = coef.digits, : NAs introduced by coercion 2: Computation failed in stat_poly_eq(): missing value where TRUE/FALSE needed No Text is output on graph
aphalo commented 3 years ago

Thanks! Can you please try to install from GitHub (Main branch) and let me know if it works correctly. I think I have fixed this bug, at least under Linux and in RStudio Cloud which I was able to test. This bug did not affect Windows on which I do the development, I think because of non-standard C-compiler behavior. Sorry about this.

lewishooper commented 3 years ago

That works!! Thanks for your help. and thanks for creating this package. It's a great help.

aphalo commented 3 years ago

Thanks for the quick feedback! Will submit the fixed version to CRAN hopefully tomorrow after some further testing. Good to know that you find the package useful!