I'm trying to adjust an equation formatting which is shown while using ggplot2 (ver. 3.3.5) and ggpmisc (ver. 0.5.1) with stat_poly_eq
.
All works just fine but for the case when the coefficients in the equation became small: the "minus" sign in the power of ten is shown in the upper position relative to the rest part of the exponent.
The ReprEx can be as below:
library(ggpmisc)
library(ggrepel)
library(broom)
v1 <- c(0.04, 0.04, 0.07, 0.07, 0.08, 0.09, 0.1, 0.1, 0.1, 0.11, 0.11, 0.12, 0.12, 0.12, 0.12, 0.13, 0.13, 0.13, 0.13, 0.14)
v2 <- c(2e-06, 1e-05, 4e-06, 2.2e-05, 1.6e-05, 1e-05, 1.8e-05, 2.6e-05, 3.4e-05, 1.7e-05, 2.8e-05, 1.4e-05, 2e-05, 2.4e-05, 2.8e-05, 2.6e-05, 3.4e-05, 3.4e-05, 4.6e-05, 2.6e-05)
ddd <- data.frame(speed = v1, dist = v2)
ggplot(ddd, aes(speed, dist)) +
geom_point() +
stat_poly_line(formula = y ~ x) +
stat_poly_eq(use_label(c("eq", "adj.R2")), formula = y ~ x)
The resulting equation I get is on the image:
How can this problem be solved?
I was trying to use geom_text
with
m <- lm(y ~ x, data = ttt)
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,
list(a = format(coef(m)[1], digits = 4),
b = format(coef(m)[2], digits = 4),
r2 = format(summary(m)$r.squared, digits = 3)))
dftext <- data.frame(x = 0, y = 0, eq = as.character(as.expression(eq)))
and
geom_text(aes(label = eq), data = dftext, parse = TRUE) +
but this piece of code didn't show anything.
The goal is to adjust symbols in an exponent of the equation coefficients.