Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created December 11, 2020 18:05
Show Gist options
  • Save jebyrnes/f5b76177b7eff77b8fe823b302274872 to your computer and use it in GitHub Desktop.
Save jebyrnes/f5b76177b7eff77b8fe823b302274872 to your computer and use it in GitHub Desktop.
make a power curve with fitted data in ggplot2
library(dplyr)
g <- tibble(x = 1:10,
y = rnorm(10, x^(0.2), 0.05))
library(ggplot2)
mod <- lm(log(y) ~ log(x), data = g)
pwr <- function(x)
exp(predict(mod, newdata = data.frame(x=x)))
ggplot(g,
aes(x = x, y = y)) +
geom_point() +
stat_function(fun = pwr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment