Create Multiple plots in the same window using par() function
To create multiple plots in the same window in the R Language, we first divide the frame into the desired grid by using the mfrow argument of the par() function. Here, we can pass a vector containing a number of rows and columns for the grid as value to argument mfrow and this will divide our frame into a grid of that number of rows and columns.
Syntax:
par( mfrow )
where,
- mfrow: determines a vector with row and column values for the grid.
Example:
In this example, basic multiple plots in R Language made using the par() function. Here, we have divided the window into a 3X2 grid and plotted plots in it.
R
# divide window into a 3X2 grid par ( mfrow= c (3,2) ) # add plots to window plot ( 1:10 ) plot ( 1:20 ) plot ( 1:30 ) plot ( 1:40 ) plot ( 1:50 ) plot ( 1:60 ) |
Output:
How to Use Par Function in R?
In this article, we will discuss how to use the par() function in the R Programming Language.
The par() function is used to set or query graphical parameters. We can divide the frame into the desired grid, add a margin to the plot or change the background color of the frame by using the par() function. We can use the par() function in R to create multiple plots at once. This helps us to create a figure arrangement with fine control.