r - 使用 ggplot 将 geom_abline 添加到来自 glm 的残差与拟合数据
问题描述
我的数据如下所示:
y = c(12, 14, 33, 50, 67, 74, 123, 141, 165, 204, 253, 246, 240)
t = 1:13
aids.pois <- glm(y~t, data=data, family="poisson")
cc <- data.frame(aids.pois$residuals, aids.pois$fitted.values)
我想将 geom_abline 添加到下面的图中,但无法显示 abline:
ggplot(cc, aes(x = aids.pois.fitted.values, y = aids.pois.residuals)) +
geom_point() +
geom_abline()
我期待这样的事情(但使用ggplot)
plot(aids.pois, which = 1, main = "base R: Residual Vs fitted plot")
解决方案
如果你想要类似于基地plot()
正在做的事情,你可以这样做
cc <- data.frame(resid=resid(aids.pois), fitted=fitted(aids.pois))
ggplot(cc, aes(x = fitted, y = resid)) +
geom_smooth(method="loess", color="red", se=FALSE) +
geom_hline(yintercept = 0, linetype=2, color="darkgrey") +
geom_point()
来自的红线plot()
只是绘制点的黄土平滑。您可以添加参考线geom_hline
。geom_abline
这里根本不需要。
推荐阅读
- c - 有没有办法在C中重复字符串中的字符?
- javascript - 浏览器标签通知
- javascript - 按日期排序数组并在重复项上增加数量
- dialog - Bot Framework SDK 4.11 DialogContextError:无法读取 undefinedTypeError 的属性“trackTrace”:无法读取未定义的属性“trackTrace”
- azure - 在 C# 中压缩 Azure Blob 文件被损坏
- c++ - 将包含自定义目标的目录导出到消费者
- flutter - 发布后如何自定义 Flutter 应用
- blazor - 将 EditForm 绑定到数组时如何让 EditContext.Validate() 工作
- c++ - 模板函数声明中函数名之后的第二个 <> 是什么?
- c# - Xamarin.Forms 5.0 NavBar BackgroudColor 在 IOS 上没有改变