[英]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.