Created
December 11, 2020 18:05
-
-
Save jebyrnes/f5b76177b7eff77b8fe823b302274872 to your computer and use it in GitHub Desktop.
make a power curve with fitted data in ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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