A line graph is chart that is used to display information in the form of series of data points. It utilizes points and lines to represent change over time. Line graphs are drawn by plotting different points on their X coordinates and Y coordinates, then by joining them together through a line from beginning to end. Graph represents different values as it can move up and down based on the suitable variable.
The plot() function in R is used to create the line graph.
Syntax:
plot(v, type, col, xlab, ylab)Parameters:
- v: This parameter is a contains only the numeric values
- type: This parameter has the following value:
- “p” : This value is used to draw only the points.
- “l” : This value is used to draw only the lines.
- “o”: This value is used to draw both points and lines
- xlab: This parameter is the label for x axis in the chart.
- ylab: This parameter is the label for y axis in the chart.
- main: This parameter main is the title of the chart.
- col: This parameter is used to give colors to both the points and lines.
Creating a Simple Line Graph
Approach: In order to create a line graph:
- It is created using the type parameter as “o” and input vector.
- Below code to describe the line graph.
Example:
# Create the data for the chart. v <- c(17, 25, 38, 13, 41) # Plot the bar chart. plot(v, type = "o") |
Output:

Adding Title, Color and Labels in Line Graph
Approach: To create colored and labeled line chart.
- Take all parameters which are required to make line chart by giving a title to the chart and add labels to the axes.
- We can add more features by adding more parameters with more colors to the points and lines.
Example:
# Create the data for the chart. v <- c(17, 25, 38, 13, 41) # Plot the bar chart. plot(v, type = "o", col = "green", xlab = "Month", ylab = "Article Written", main = "Article Written chart") |
Output:

Multiple Lines in a Line Graph
Approach: To create multiple line graphs.
- In above example, we created line graphs by only one line in each graph.
- Now creating multiple lines to describe it more clearly.
Example:
# Create the data for the chart. v <- c(17, 25, 38, 13, 41) t <- c(22, 19, 36, 19, 23) m <- c(25, 14, 16, 34, 29) # Plot the bar chart. plot(v, type = "o", col = "red", xlab = "Month", ylab = "Article Written ", main = "Article Written chart") lines(t, type = "o", col = "blue") lines(m, type = "o", col = "green") |
Output: When we execute the above code, it shows the following result-

Recommended Posts:
- How to read a file line by line using node.js ?
- How to Read a File Line by Line to String in Golang?
- Plotting Graphs using Two Dimensional List in R Programming
- R - Charts and Graphs
- Introduction to Graphs
- Class 8 NCERT Solutions - Chapter 15 Introduction to Graphs - Exercise 15.3
- Class 8 NCERT Solutions - Chapter 15 Introduction to Graphs - Exercise 15.1
- Class 8 NCERT Solutions - Chapter 15 Introduction to Graphs - Exercise 15.2
- How to break line without using <br> tag in HTML / CSS ?
- How to prevent line breaks in the list of items using CSS?
- How to put string in array, split by new line in PHP ?
- CSS | text-decoration-line Property
- How to make a vertical line using HTML ?
- Command Line Argument in Scala
- How to remove line breaks from the string in PHP?
- How to insert line break before an element using CSS?
- How to create multi-line strings in JavaScript?
- How to make horizontal line with words in the middle using CSS?
- How to remove all line breaks from a string using JavaScript?
- Perl | Use of Hash bang or Shebang line
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.

