将线性回归线添加到 R 上的 ggplot2 点图

Adding linear regression line to ggplot2 dotplot on R

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

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)

ladder = 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), labels = trans_format('log10',math_format(10^.x)))

我试过 >geom_smooth、>geom_abline 和 >stat_smooth。 None 这些作品。非常感谢您的帮助。

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

这段代码对我有用。

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")

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