** segment()** function in R Language is used to draw a line segment between to particular points.

Syntax:segments(x0, y0, x1, y1)

Parameters:

x, y:coordinates to draw a line segment between provided points.

Returns:a line segment between given points

**Example 1: **To draw a single line segment

`# Create empty example plot ` `plot` `(0, 0, col = ` `"white"` `, xlab = ` `""` `, ylab = ` `""` `) ` ` ` `# Draw one line ` `segments` `(x0 = - 1, y0 = - 0.5, x1 = 0.5, y1 = 0, col = ` `"darkgreen"` `) ` |

*chevron_right*

*filter_none*

**Output:**

Here, x0 & y0 are starting points of the line segment and x1 & y1 are ending points of line segment .

**Example 2: **Modifying color, thickness & line type

`# Create empty example plot ` `plot` `(0, 0, col = ` `"white"` `, xlab = ` `""` `, ylab = ` `""` `) ` ` ` `# Draw one line as in Example 1 ` `segments` `(x0 = - 1, y0 = - 1, x1 = 0.5, y1 = 0.5, ` ` ` ` ` `# Color of line ` ` ` `col = ` `"darkgreen"` `, ` ` ` ` ` `# Thickness of line ` ` ` `lwd = 5, ` ` ` ` ` `# Line type ` ` ` `lty = ` `"dotted"` `) ` |

*chevron_right*

*filter_none*

**Output:**

**Example 3: **Draw multiple line segments to R Plot.

`# Create empty example plot ` `plot` `(0, 0, col = ` `"white"` `, xlab = ` `""` `, ylab = ` `""` `) ` ` ` `# Create data frame with line-values ` `multiple_segments <- ` `data.frame` `(x0 = ` `c` `(0.1, 0.2, - 0.7, 0.4, - 0.8), ` ` ` `y0 = ` `c` `(0.8, 0.3, 0.5, - 0.4, 0.3), ` ` ` `x1 = ` `c` `(0, 0.4, 0.5, - 0.5, - 0.7), ` ` ` `y1 = ` `c` `(- 0.3, 0.4, - 0.5, - 0.7, 0.8)) ` ` ` ` ` `# Draw multiple lines ` ` ` `segments` `(x0 = multiple_segments$x0, ` ` ` `y0 = multiple_segments$y0, ` ` ` `x1 = multiple_segments$x1, ` ` ` `y1 = multiple_segments$y1) ` |

*chevron_right*

*filter_none*

**Output:**

## Recommended Posts:

- Draw a Polygon between specified points in R Programming - polygon() Function
- Addition of more points to a Plot in R Programming - points() Function
- Draw a Quantile-Quantile Plot in R Programming - qqline() Function
- Add Color Between Two Points of Kernel Density Plot in R Programming - Using with() Function
- Plot Arrows Between Points in a Graph in R Programming - arrows() Function
- Get a List of points obtained by Interpolation in R Programming - spline() and splinefun() Function
- Create Line Curves for Specified Equations in R Programming - curve() Function
- Check if a numeric value falls between a range in R Programming - between() function
- Check if a Function is a Primitive Function in R Programming - is.primitive() Function
- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Check for Presence of Common Elements between Objects in R Programming - is.element() Function
- Calculate the difference between Consecutive pair of Elements of a Vector in R Programming - diff() Function
- Compute the Covariance between Two Vectors in R Programming - cov() Function
- Compute the Correlation Coefficient Value between Two Vectors in R Programming - cor() Function
- Calculate Time Difference between Dates in R Programming - difftime() Function
- Find positions of Matching Elements between Vectors in R Programming - match() Function
- Find the Difference Between Two Dates in R Programming - julian() Function
- Create a Range of Colors between the Specified Colors in R Programming - colorRampPalette() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Apply a Function over a List of elements in R Programming - lapply() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.