# R Line Plots

Line plots generate a graph by drawing line segments between two points. We can plot a line graph using plot() function.

### Syntax of line plot

`plot(x,type,col,xlab,ylab,main)`

Here, x is the data to plot on a graph, xlab and ylab are the levels for x and y axis respectively, the col attribute sets the color of a line segment and the main attribute is to give a title to the graph.

The type attribute is of the following types -

- 'p' - points
- 'l' - lines
- 'b' - both points and lines
- 'c' - empty points joined by lines
- 'o' - overplotted points and lines
- 's' - stair steps

## Example1 of R Line Plots

Here, we are taking a very simple example to plot the variation of speed over time as an index. We store the speed in a vector.

```
Speed <- c(50, 55, 50, 60, 65, 55)
plot(speed, type='I')
```

## Example2 of R Line Plots

In this example, we will build an advance graph. Suppose, we have per day sales record, so here we plot the current week sales record in line graph, also we set the color, give name to the x axis and y axis and set the name of the graph.

```
Sales <- c(1000, 1100, 1300, 1250, 1200, 1220, 1300)
plot(Sales, type='o', col='blue', xlab='Days', ylab='Sales', main='Weekly Sales')
```

The above code generates this graph.