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!
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.
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=".
If you want to add the 1:1 diagonal line:
qplot(1,1) + geom_abline(intercept = 0, slope = 1)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With