向“绘图”散点图添加回归线的问题。 我已经完成了以下代码:
## Adding regression line (HERE IS THE PROBLEM) ##
g <- add_trace(c,
x = Wind,
y = fitted(lm(Ozone ~ Wind, airquality)),
mode = "lines"
)
g
https://angular.io/docs/ts/latest/cookbook/set-document-title.html
{{1}}
答案 0 :(得分:5)
我认为这是由缺失值引起的
airq <- airquality %>%
filter(!is.na(Ozone))
fit <- lm(Ozone ~ Wind, data = airq)
airq %>%
plot_ly(x = ~Wind) %>%
add_markers(y = ~Ozone) %>%
add_lines(x = ~Wind, y = fitted(fit))
答案 1 :(得分:0)
使用布局删除图例,并跟踪以添加回归线
data("airquality")
fv <- airquality %>% filter(!is.na(Ozone)) %>% lm(Ozone ~ Wind,.) %>% fitted.values()
airquality %>% filter(!is.na(Ozone)) %>%
plot_ly(x = ~Wind, y = ~Ozone, mode = "markers") %>%
add_markers(y = ~Ozone) %>%
add_trace(x = ~Wind, y = fv, mode = "lines") %>%
layout(showlegend = F)