如何在图中添加对角线?

Jun*_*hao 10 r line scatter-plot ggplot2

我想在情节中添加对角线.它不是线性回归线.我只想要一个诊断线.谁能帮我这个?非常感谢!

Len*_*ert 12

如果要添加1:1对角线:

qplot(1,1) + geom_abline(intercept = 0, slope = 1)
Run Code Online (Sandbox Code Playgroud)


小智 9

你可以使用 abline()

abline(coef = c(0,1))
Run Code Online (Sandbox Code Playgroud)

这为您提供了一条来自现有图中斜率为 1 的截距 0 的线。

如果您希望该线与任何图成对角线,只需将截距设置为左下角,并将斜率设置为两个轴之间的增加比率。


kil*_*les 8

lines(x = c(0,100), y = c(0,100))
Run Code Online (Sandbox Code Playgroud)