Ggvis with 95% prediction interval
library(ggvis)
mtcars %>%
ggvis(~wt, ~mpg) %>%
layer_points() %>%
layer_model_predictions(model = "lm", se = TRUE)
The above plot gives a scatter plot with a fixed regression line and 95% confidence limits at .
Question . How to draw a scatter plot with a regression line set and 95% prediction limits at ?
+3
source to share
1 answer
Here's an idea. You probably need to work harder to get what you need.
mtcars.pi = data.frame(mtcars, predict(lm(mpg~wt,data=mtcars), interval="prediction"))
mtcars.pi %>%
ggvis(~wt, ~mpg) %>%
layer_points() %>%
layer_ribbons(y=~lwr, y2=~upr, opacity:=.5) %>%
layer_model_predictions(model = "lm", se = TRUE)
0
source to share