R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
The plot() function is used to draw points (marks) in a drawing.
The function takes parameters to specify points in a drawing.
Parameter 1 specifies points in x-axis.
Parameter 2 specifies points on the y-axis.
For its simplicity, you can use the plot() function to arrange two numbers against each other:
Draw one point in the diagram, at position (1) and position (3):
To draw additional points, use vectors:
Draw two points in the diagram, one at position (1, 3) and one in position (8, 10):
You can edit as many points as you like, just make sure you have the same number of points on both axis:
For better organization, if you have a lot of values, it is best to use a variable:
If you want to draw dots in sequence, for both x-axis and y-axis, use : operator:
The plot() function also takes a type of parameter with the value l of drawing a line to connect all the points in a drawing:
The plot() function also accepts other parameters, such as main, xlab and ylab if you want to customize the graph with the main heading and the different x and y axis labels:
There are many other parameters you can use to change the look of the points.
Use col = "color" to add color to points:
Use cex = number to change point size (1 is default, and 0.5 means 50% less, and 2 means 100% greater):
Use a pch with a value from 0 to 25 to change the format of the point:
Pch parameter values range from 0 to 25, which means we can choose up to 26 different types of points: