Inspired by the post you linked. Use geom_text
to add the label after extracting parameters.
nlsFit <-
nls(formula = mpg ~ k * e ^ wt,
start = list(k = 1, e = 2),
data = mtcars)
nlsParams <-
nlsFit$m$getAllPars()
nlsEqn <-
substitute(italic(y) == k %.% e ^ italic(x),
list(k = format(nlsParams['k'], digits = 4),
e = format(nlsParams['e'], digits = 2)))
nlsTxt <-
as.character(as.expression(nlsEqn))
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
stat_fit_augment(method = "nls",
method.args = args) +
geom_text(x = 5, y = 30, label = nlsTxt, parse = TRUE)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…