我进行了回归分析。
现在我需要创建情节depended vs prediction
,其中depend是依赖变量(mpg)的初始值,而预测是预测值。
house_test=lm(mpg ~ 1 + hp + wt, data=mtcars)
prediction <- as.data.frame(predict(house_test, mtcars,
interval = 'prediction',
level = .95))
prediction$mpg <- mtcars$mpg
ggplot(prediction) +
geom_ribbon(aes(mpg, ymin = lwr, ymax = upr), fill = 'lightskyblue', alpha = 0.5) +
geom_point(aes(mpg, fit), alpha = 0.2) +
labs(title = "interval 95%CI", y = "depend", x = "predict")
如何在依赖与预测的情节中添加对角线(黄色)? 注意Y轴是相关的var,X asis是预测值。
答案 0 :(得分:1)
ggplot(prediction) +
geom_ribbon(aes(mpg, ymin = lwr, ymax = upr), fill = 'lightskyblue', alpha = 0.5) +
geom_point(aes(mpg, fit), alpha = 0.2) +
labs(title = "interval 95%CI", y = "depend", x = "predict") +
geom_abline(intercept = 0, slope = 1, col="yellow")