Subplots in R
Learn how to create more than one chart in the output.
We'll cover the following...
In data analysis, we frequently need to create more than one chart to compare different datasets side by side, which may help us spot useful trends and patterns.
Also, we use supplementary charts to provide additional information to our audience. This helps us to convey our story in a more comprehensive style.
Subplots in base R
We use the par()
function before the plot
functions to output different charts next to each other. It allows us to design a layout for the charts that we will create. We use the plot
functions after the par()
function as usual. Here are the arguments that the function can take:
-
mfrow
andmfcol
: These set the layout of the plotting region in terms of rows and columns. The plots are filled into the matrix by rows as per themfrow
value and by columns as per themfcol
value.
If we setmfcol = c(2,3)
, there will be ...