VOOZH about

URL: https://www.geeksforgeeks.org/r-language/adding-straight-lines-to-a-plot-in-r-programming-abline-function/

⇱ Adding Straight Lines to a Plot in R Programming - abline() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Adding Straight Lines to a Plot in R Programming - abline() Function

Last Updated : 15 Jul, 2025
abline() function in R Language is used to add one or more straight lines to a graph. The abline() function can be used to add vertical, horizontal or regression lines to plot.
Syntax: abline(a=NULL, b=NULL, h=NULL, v=NULL, ...) Parameters: a, b: It specifies the intercept and the slope of the line h: specifies y-value for horizontal line(s) v: specifies x-value(s) for vertical line(s) Returns: a straight line in the plot
Example 1: To add a vertical line to the plot

Output:

👁 Image
👁 Image
👁 Image

Here, in above example straight line is added using abline() to different graphical plots


Example 2: To add a horizontal line

Output:

👁 Image

In above example abline() Function draws an horizontal line on the current plot at the specified ‘x’ coordinates.

Example 3: To add a regression line

Output:

👁 Image
In the above example, straight-line is added using the line equation and abline() function and plot relation between speed and distance.
Comment
Article Tags:

Explore