The plot()
function in R is used to draw or create graphs and charts for visualizations. In simple terms, the plot()
function is used to return a plot of a number(s) against another number(s).
plot(x, y)
The plot()
function takes two parameter values:
x
: Represents points on the x-axis of the plot.y
: Represents points on the y-axis of the plot.Let’s create a plot of the number 2
against 6
using the plot()
function.
plot(2, 6)
The plot()
function can also be used to draw two points in a diagram, where one point represents a position at (x, y) and another represents another position at (x, y).
plot(c(2, 6), c(4, 12))
For a number of points, one needs to provide the same number of points for both axes.
# creating equal axisx <- c(1, 2, 3, 4, 5)y <- c(3, 6, 9, 12, 15)# implementing the plot() functionplot(x, y)
x
and y
axis, respectively. We use their corresponding names (x
and y
) as their variable names.x
and y
axis using the plot()
function.