[英]Regression Line is Not Plotting When Using Geom_Smooth
我正在 Kaggle 上进行为期 5 天的回归挑战,但在使用 ggplot 时,我无法获得 plot 的泊松回归线。 我想看看下雨对穿过纽约市桥梁的自行车数量的影响。
我试过颠倒 geom_point 和 geom_smooth 的顺序,但没有奏效。 如果我改用高斯,那也行不通。
这是我写的:
ggplot(data = bikes, mapping = aes(x = Precipitation, y = Total)) +
geom_smooth(method = "glm", method.args = list(family = "poisson")) +
geom_point() +
labs(title = 'Precipitation vs. Total Bike Crossings')
在绘制数据之前检查数据:
unique(bikes$Precipitation)
# [1] "0.01" "0.15" "0.09" "0.47 (S)" "0" "0.2" "T"
# [8] "0.16" "0.24" "0.05"
回归量Precipitation
不是数字,当强制转换为数字时,它的一些值将变为NA
值。
如果您先强制Precipitation
,则会出现回归线。
library(dplyr)
library(ggplot2)
bikes %>%
mutate(Precipitation = as.numeric(Precipitation)) %>%
na.omit() %>%
ggplot(mapping = aes(x = Precipitation, y = Total)) +
geom_smooth(method = "glm",
formula = y ~ x,
method.args = list(family = "poisson")) +
geom_point() +
labs(title = 'Precipitation vs. Total Bike Crossings')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.