情节 - 如何使用R添加每种颜色的多个回归?
我的情节是将所有回归线彼此堆叠在一起。
mod = lm(weight_kg ~ height_cm, data=rugby_data)
fig2 <- plot_ly(rugby_data, x = ~height_cm, y = ~weight_kg, type="scatter", mode="markers", color = rugby_data$continent) %>%
add_lines(x = rugby_data$height_cm,y = fitted(mod), name="fitted", mode = "lines") %>%
layout(title = 'Height Vs. Weight Scatter Plot', plot_bgcolor = "#e5ecf6")
fig2
My plot is stacking all the regression lines on top of each other.
mod = lm(weight_kg ~ height_cm, data=rugby_data)
fig2 <- plot_ly(rugby_data, x = ~height_cm, y = ~weight_kg, type="scatter", mode="markers", color = rugby_data$continent) %>%
add_lines(x = rugby_data$height_cm,y = fitted(mod), name="fitted", mode = "lines") %>%
layout(title = 'Height Vs. Weight Scatter Plot', plot_bgcolor = "#e5ecf6")
fig2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
lm
对象不适合组(我猜是concodant
),如果您的目的是绘制点和回归行,
您可以尝试使用
ggplot2
ggplot2 < /代码>。
由于您没有提供您的数据,因此我以
iris
为例。Your
lm
object did not fit model by groups(I guess it'scontinent
)If your purpose is to plot the points and regression lines,
you may try using
ggplot2
.As you did not provide your data, I use
iris
as an example.