0
学习ggplot2并不明白为什么第二组代码会产生错误。我所要做的就是在第三组代码中添加美学到stat_smooth命令,并且它运行良好,但我不明白为什么。ggplot2中的逻辑回归模型
ggplot(df, aes(x=wave.height, y=ship.deploy)) + geom_point() +
stat_smooth(method="glm", method.args=list(family="binomial"), se=FALSE)
ggplot(data = df) +
geom_point(mapping = aes(x = wave.height, y = ship.deploy)) +
stat_smooth(method = "glm", method.args = list(family = "binomial"), se = FALSE)
Error: stat_smooth requires the following missing aesthetics: x, y
ggplot(data = df) +
geom_point(mapping = aes(x = wave.height, y = ship.deploy)) +
stat_smooth(mapping = aes(x = wave.height, y = ship.deploy),method = "glm", method.args = list(family = "binomial"), se = FALSE)
我已投票结束此问题,因为它与统计数据无关。 – SmallChess
在第一个示例中,您在'ggplot'中全局映射'x'和'y'。这些全球美学传递到其余层次。在第二个例子中,你不使用全局美学,而只是在'geom_point'图层中映射'x'和'y'。这些不会传递给其他图层,因此'stat_smooth'没有'x'和'y'美学用途,并且会出现错误。 – aosmith