ggplot() +
geom_point(aes(x = Africa_set$Africa_Predict, y = Africa_set$Africa_Real), color ="red") +
geom_line(aes(x = Africa_set$Africa_Predict, y = predict(simplelm, newdata = Africa_set)),color="blue") +
labs(title = "Africa Population",fill="") +
xlab("Africa_set$Africa_Predict") +
ylab("Africa_set$Africa_Real")然后显示错误消息:
Error: Found object is not a stat如何修复此错误?
发布于 2017-05-01 18:34:04
看起来你在试图用拟合的回归线在上面画点。您可以使用以下方法来完成此操作:
library(ggplot2)
ggplot(iris, aes(Petal.Length, Petal.Width)) +
geom_point() +
geom_smooth(method = "lm")或者,如果您确实想像在示例中那样使用预先存储在simplelm对象中的模型,可以使用扫帚包中的augment:
library(ggplot2)
library(broom)
simplelm <- lm(Petal.Width ~ Petal.Length, data = iris)
ggplot(data = augment(simplelm),
aes(Petal.Length, Petal.Width)) +
geom_point() +
geom_line(aes(Petal.Length, .fitted), color = "blue")https://stackoverflow.com/questions/43723464
复制相似问题