aphalo / ggpmisc

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

stat_poly_eq > eq.label does not show "x" when using formula y~x+0. #10

Closed orgadish closed 3 years ago

orgadish commented 3 years ago

Running ggpmisc 0.4.0 R version 4.0.3 (2020-10-10) MacOS X 11.2.3 x86_64-apple-darwin17.0

library(tibble)
library(ggplot)
library(ggpmisc)

set.seed(0); tibble(a=1:100, b=runif(length(a), 0.7, 1.3) * (a*5)) %>% 
  ggplot(aes(a,b))+
  geom_point()+
  stat_poly_eq(aes(label=stat(eq.label)), formula=y~x, parse=T)

set.seed(0); tibble(a=1:100, b=runif(length(a), 0.7, 1.3) * (a*5)) %>% 
  ggplot(aes(a,b))+
  geom_point()+
  stat_poly_eq(aes(label=stat(eq.label)), formula=y~x+0, parse=T)
  1. Running first chunk displays the equation y = -0.603 + 5.06 x
  2. Running second chunk displays the equation y = 5.05 instead of y = 5.05 x
aphalo commented 3 years ago

@orgadish Thanks for reporting this. Until I fix this bug you can use the y ~ x - 1 notation, which is equivalent and supported.

orgadish commented 3 years ago

@aphalo, thanks. I didn't realize y ~ x - 1 is equivalent. Just found the section in the help for formula that clarifies.

aphalo commented 3 years ago

@orgadish Bug fixed now in GitHub. I did the opposite when writing the package... forgot to handle + 0 as I always use - 1 myself.