ggplot2 - R - tidy augment confidence interval -
i wondering how can compute confidence interval using broom package.
what trying simple , standard :
set.seed(1) x <- runif(50) y <- 2.5 + (3 * x) + rnorm(50, mean = 2.5, sd = 2) dat <- data.frame(x = x, y = y) mod <- lm(y ~ x, data = dat) using visreg can plot regression models ci :
library(visreg) visreg(mod, 'x', overlay=true) i interesting in reproducing using broom , ggplot2, far achieved :
library(broom) dt = lm(y ~ x, data = dat) %>% augment(conf.int = true) ggplot(data = dt, aes(x, y, colour = y)) + geom_point() + geom_line(data = dt, aes(x, .fitted, colour = .fitted)) the augment funciton doesn't compute conf.int. clue how can add smooth confidence invervals ?
geom_smooth(data=dt, aes(x, y, ymin=lcl, ymax=ucl), size = 1.5, colour = "red", se = true, stat = "smooth")
using broom output, can this:
ggplot(data = dt, aes(x, y)) + geom_ribbon(aes(ymin=.fitted-1.96*.se.fit, ymax=.fitted+1.96*.se.fit), alpha=0.2) + geom_point(aes(colour = y)) + geom_line(aes(x, .fitted, colour = .fitted)) + theme_bw() i moved colour=y geom_point() because can't apply colour aesthetic geom_ribbon.



Comments
Post a Comment