# How to draw gridlines in a graph with abline function in R?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

Gridlines are the horizontal and vertical dotted lines, and they help to organize the chart so that the values on the labels becomes better readable to viewers. This is helpful specially in situations where we plot a large number of data points. A graph drawn by plot function can have gridlines by defining the vertical and horizontal lines using abline.

## Example

Consider the below data and scatterplot −

Live Demo

> x<-rnorm(10)
> y<-rnorm(10,1.5)
> plot(x,y)

## Output

Adding gridlines using abline function −

> abline(h=seq(0,5,0.5),lty=5)
> abline(v=seq(-2,2,0.5),lty=5)

## Output

Updated on 04-Sep-2020 12:21:34