How to add a diagonal line to the plot?

I want to add a diagonal line to the plot. This is not a linear regression line. I just want a line of diagnosis. Can anyone help me with this? Thank you very much!

+6
source share
5 answers
lines(x = c(0,100), y = c(0,100)) 
+7
source

If you want to add a 1: 1 diagonal line:

 qplot(1,1) + geom_abline(intercept = 0, slope = 1) 
+6
source

If you do not want your line to expand across the entire plot range, or if you want to add arbitrary line segments, use segments . For example, the following code draws a square:

 plot.new() plot.window(xlim = c(0, 3), ylim = c(0, 3)) segments(x0=c(1,1,2,2), x1=c(1,2,2,1), y0=c(1,2,2,1), y1=c(2,2,1,1)) 
0
source

this adds a diagonal line to ggplot,

 qplot(1,1) + annotation_custom(linesGrob(c(0,1), c(0,1))) 

or equivalently

 qplot(1,1) + annotate("segment", x=-Inf, xend=Inf,y=-Inf, yend=Inf) 
0
source

To add a line, for example, from x = -3, y = -3 to x = 3, y = 3:

segments(-3,-3,3,3)

-1
source

Source: https://habr.com/ru/post/979564/


All Articles