My problem is when I plot the same data with linear and with log-transformed axes, the equation that is calculated by stat_poly_eq gives is different between both plots (wrong in the log-transformed plot). What could be the reason for that, and is there a simple way to fix that?
See below code for example:
library(ggplot2)
x <- runif(100, min = 10, max = 1000)
y <- 2 * x + rnorm(100, mean = 0, sd = 50)
df <- data.frame(x = x, y = y)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = "lm") +
stat_poly_eq(formula = y ~ x, use_label(c("eq", "adj.R2", "n")))
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = "lm") +
scale_x_continuous(trans = "log10") +
scale_y_continuous(trans = "log10") +
stat_poly_eq(formula = y ~ x, use_label(c("eq", "adj.R2", "n")))