将回归线更改为直形状

发布于 2025-02-11 19:11:35 字数 328 浏览 1 评论 0原文

我实际上是在R.中建立了我的第一个线性回归,我偶然发现了最后一步:您能建议如何将我的垫脚线性回归更改为直线吗?我可以添加简单的可视化命令吗?我写的代码是:

MyDataSet.plot <- MyDataSet.plot + 
   geom_line(data=plotting.data2, 
             aes(x=MyXvariable, y=predicted.y, color=MyOtherIndependentVariable), 
             size=1.25) 
MyDataSet.plot

请对我说非常小的r :)谢谢

I'm literally building my first ever linear regression in R. And I stumbled on the very last step: could you advise how to change my stepped linear regression into straight line? Is there simple visualisation command I can add? The code I wrote is:

MyDataSet.plot <- MyDataSet.plot + 
   geom_line(data=plotting.data2, 
             aes(x=MyXvariable, y=predicted.y, color=MyOtherIndependentVariable), 
             size=1.25) 
MyDataSet.plot

Please speak very elementary R to me :) Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别理我 2025-02-18 19:11:35

这个最小的例子是您要实现的目标吗?

library(tidyverse)

# Sample data
df <- tribble(~x, ~y, ~col,
        1, 3, "a",
        2, 5, "a",
        3, 4, "a",
        4, 5, "a",
        1, 6, "b",
        2, 7, "b",
        3, 7, "b",
        4, 9, "b"
        )

# Plot
ggplot(df, aes(x, y, colour = col)) +
  geom_line() +
  geom_smooth(method = "lm", se = FALSE, linetype = "dashed")
#> `geom_smooth()` using formula 'y ~ x'

“”

在2022-06-30创建的 reprex软件包(v2.0.1)

Is this minimal example what you'd like to achieve?

library(tidyverse)

# Sample data
df <- tribble(~x, ~y, ~col,
        1, 3, "a",
        2, 5, "a",
        3, 4, "a",
        4, 5, "a",
        1, 6, "b",
        2, 7, "b",
        3, 7, "b",
        4, 9, "b"
        )

# Plot
ggplot(df, aes(x, y, colour = col)) +
  geom_line() +
  geom_smooth(method = "lm", se = FALSE, linetype = "dashed")
#> `geom_smooth()` using formula 'y ~ x'

Created on 2022-06-30 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文