stat_poly_eq not working with log-transformed axis

Create issue
Issue #41 closed
Former user created an issue

I have experienced some unusual behaviour in the stat_poly_eq function from the ggpmisc package, that I suspect is a bug. If you draw the exact same with and without scaling the axes, then you'll get different estimates. This is very surprising behavior. Why should changing the scale of the graphical representation change the underlying model?

mtcars
lm_eq = y~x

ggplot(mtcars, aes(disp, drat)) +
  geom_point() +
  geom_smooth(method = "lm",formula=lm_eq) +
  scale_x_continuous(trans = "log10") +
  scale_y_continuous(trans = "log10") +
  theme_bw()+
  facet_wrap(~cyl) +
  stat_poly_eq(
    aes(label = paste(stat(adj.rr.label), stat(eq.label),sep = "*\", \"*")),
    formula = lm_eq, rr.digits = 2, parse = TRUE,size=3)

vs.

ggplot(mtcars, aes(disp, drat)) +
  geom_point() +
  geom_smooth(method = "lm",formula=lm_eq) +
   theme_bw()+
  facet_wrap(~cyl) +
  stat_poly_eq(
    aes(label = paste(stat(adj.rr.label), stat(eq.label),sep = "*\", \"*")),
    formula = lm_eq, rr.digits = 2, parse = TRUE,size=3)

Comments (2)

  1. Pedro J. Aphalo repo owner

    This is how ggplot works. Fitting of the smoother is done after scale transformations are applied, as can be seen the lines are straight in spite of the transformation. stat_poly_equation() gives the equation for this plotted line.

  2. Log in to comment