我的数据是这样的:
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 a bline,但无法显示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() 正在做,你可以做这个
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()
红线来自 标号() 只是一个黄土平滑的绘制点。您可以使用 geom_hline . 不需要 geom_abline 在这里。
标号()
geom_hline
geom_abline