Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a diagonal line to a plot?

I want to add a diagonal line to the plot. It is not a linear regression line. I just want a diagnol line. Can anyone help me with this? Thanks a lot!

like image 680
Junhua Zhao Avatar asked Dec 14 '14 01:12

Junhua Zhao


People also ask

How do you add a line to a plot?

Use the lines() Function to Add a Line to a Plot in R Note that the second argument, which denotes the y-axis coordinates, is optional. Once the plot is drawn, we can call the lines() function and pass the coordinate vectors as needed to add lines to the plot.

How do I draw a diagonal line in Matplotlib?

Plotting a diagonal line based from the bottom-left to the top-right of the screen is quite simple, you can simply use ax. plot(ax. get_xlim(), ax. get_ylim(), ls="--", c=".


2 Answers

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

qplot(1,1) + geom_abline(intercept = 0, slope = 1)
like image 149
Lennert Avatar answered Sep 19 '22 02:09

Lennert


You could use abline()

abline(coef = c(0,1))

this gives you a line from intercept 0 with slope 1 in an existing plot.

If you want the line to be diagonal to any plot just set the intercept to the lower left corner and the slope to the ratio of increase between the two axis.

like image 25
Peter Hartog Avatar answered Sep 18 '22 02:09

Peter Hartog