[英]plotly regression line R
將回歸線添加到“情節”散點圖時出現問題。 我已經完成了以下代碼:
require(plotly)
data(airquality)
## Scatter plot ##
c <- plot_ly(data = airquality,
x = Wind,
y = Ozone,
type = "scatter",
mode = "markers"
)
c
## Adding regression line (HERE IS THE PROBLEM) ##
g <- add_trace(c,
x = Wind,
y = fitted(lm(Ozone ~ Wind, airquality)),
mode = "lines"
)
g
使用layout去掉圖例,trace增加回歸線
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.