- R - Data Reshaping
- R - Packages
- R - Data Frames
- R - Factors
- R - Arrays
- R - Matrices
- R - Lists
- R - Vectors
- R - Strings
- R - Functions
- R - Loops
- R - Decision Making
- R - Operators
- R - Variables
- R - Data Types
- R - Basic Syntax
- R - Environment Setup
- R - Overview
- R - Home
R Data Interfaces
- R - Database
- R - Web Data
- R - JSON Files
- R - XML Files
- R - Binary Files
- R - Excel Files
- R - CSV Files
R Charts & Graphs
R Statistics Examples
- R - Chi Square Tests
- R - Survival Analysis
- R - Random Forest
- R - Decision Tree
- R - Nonlinear Least Square
- R - Time Series Analysis
- R - Analysis of Covariance
- R - Poisson Regression
- R - Binomial Distribution
- R - Normal Distribution
- R - Logistic Regression
- R - Multiple Regression
- R - Linear Regression
- R - Mean, Median & Mode
R Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
R - Line Graphs
A pne chart is a graph that connects a series of points by drawing pne segments between them. These points are ordered in one of their coordinate (usually the x-coordinate) value. Line charts are usually used in identifying the trends in data.
The plot() function in R is used to create the pne graph.
Syntax
The basic syntax to create a pne chart in R is −
plot(v,type,col,xlab,ylab)
Following is the description of the parameters used −
v is a vector containing the numeric values.
type takes the value "p" to draw only the points, "l" to draw only the pnes and "o" to draw both points and pnes.
xlab is the label for x axis.
ylab is the label for y axis.
main is the Title of the chart.
col is used to give colors to both the points and pnes.
Example
A simple pne chart is created using the input vector and the type parameter as "O". The below script will create and save a pne chart in the current R working directory.
# Create the data for the chart. v <- c(7,12,28,3,41) # Give the chart file a name. png(file = "pne_chart.jpg") # Plot the bar chart. plot(v,type = "o") # Save the file. dev.off()
When we execute the above code, it produces the following result −
Line Chart Title, Color and Labels
The features of the pne chart can be expanded by using additional parameters. We add color to the points and pnes, give a title to the chart and add labels to the axes.
Example
# Create the data for the chart. v <- c(7,12,28,3,41) # Give the chart file a name. png(file = "pne_chart_label_colored.jpg") # Plot the bar chart. plot(v,type = "o", col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart") # Save the file. dev.off()
When we execute the above code, it produces the following result −
Multiple Lines in a Line Chart
More than one pne can be drawn on the same chart by using the pnes()function.
After the first pne is plotted, the pnes() function can use an additional vector as input to draw the second pne in the chart,
# Create the data for the chart. v <- c(7,12,28,3,41) t <- c(14,7,6,19,3) # Give the chart file a name. png(file = "pne_chart_2_pnes.jpg") # Plot the bar chart. plot(v,type = "o",col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart") pnes(t, type = "o", col = "blue") # Save the file. dev.off()
When we execute the above code, it produces the following result −
Advertisements