Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
plot
communitycreator

# What is the plot() function in R? Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

### Overview

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).

### Syntax

plot(x, y)


### Parameters

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.

### Example 1

Let’s create a plot of the number 2 against 6 using the plot() function.

plot(2, 6)
Implementing the plot() function
Output of the code

### Example 2

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))
Implementing the plot() function for two points
Output of the code

### Example 3

For a number of points, one needs to provide the same number of points for both axes.

# creating equal axis
x <- c(1, 2, 3, 4, 5)
y <- c(3, 6, 9, 12, 15)

# implementing the plot() function
plot(x, y)
Implementing the plot() function for multiple points
Implementing the plot() function for multiple points

### Explanation

• Lines 2 and 3: We create the values of the points in the x and y axis, respectively. We use their corresponding names (x and y) as their variable names.
• Line 6: We plot the various points in the x and y axis using the plot() function.

RELATED TAGS

function
r
plot
communitycreator

CONTRIBUTOR Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 