【问题标题】:Adding linear regression line to ggplot2 dotplot on R将线性回归线添加到 R 上的 ggplot2 dotplot
【发布时间】:2016-08-01 01:19:59
【问题描述】:

我想在半对数点图中添加一条线性回归线,但我似乎无法让它工作。

mm= c(44.637, 41.252, 38.717, 36.176, 34.275, 32.366, 30.676, 29.407, 27.715, 26.866)

bp = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)

梯形图 = data.frame(mm, bp)

ggplot2.dotplot(data=ladder, xName='bp', yName='mm', mainTitle='Ladder') + scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x), 标签= trans_format('log10',math_format(10^.x)))

我尝试过 >geom_smooth、>geom_abline 和 >stat_smooth。这些都不起作用。非常感谢您的帮助。

【问题讨论】:

    标签: r plot ggplot2 linear-regression graphing


    【解决方案1】:

    dotplot 不适用于此数据。我认为您正在寻找散点图。

    这段代码对我有用。

    ggplot(ladder, aes(bp, mm)) + geom_point() +  
    scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x), labels =  trans_format('log10',math_format(10^.x))) +
    geom_smooth(method ="lm")
    

    在平滑函数中,method = "lm" 拟合线性回归线

    【讨论】:

      猜你喜欢
      • 2015-01-02
      • 1970-01-01
      • 2021-01-21
      • 2021-03-25
      • 1970-01-01
      • 2016-11-07
      • 2016-01-31
      • 2013-02-11
      • 1970-01-01
      相关资源
      最近更新 更多