English 中文(简体)
ggplot2 - Multi Panel Plots
  • 时间:2024-11-03

ggplot2 - Multi Panel Plots


Previous Page Next Page  

Multi panel plots mean plot creation of multiple graphs together in a single plot. We will use par() function to put multiple graphs in a single plot by passing graphical parameters mfrow and mfcol.

Here we will use “AirQuapty” dataset to implement multi panel plots. Let us understand the dataset first to have a look on creation of multi panel plots. This dataset includes Contains the responses of a gas multi-sensor device deployed on the field in an Itapan city. Hourly responses averages are recorded along with gas concentrations references from a certified analyzer.

Insight of par() function

Understand the par() function to create a dimension of required multi panel plots.


> par(mfrow=c(1,2))
> # set the plotting area into a 1*2 array

This creates a blank plot with dimension of 1*2.

Insight of par() Function

Now create the bar plot and pie chart of the mentioned dataset using following command. This same phenomenon can be achieved with the graphical parameter mfcol.

Creating Multi Panel Plots

The only difference between the two is that, mfrow fills in the subplot region row wise while mfcol fills it column wise.


> Temperature <- airquapty$Temp
> Ozone <- airquapty$Ozone
> par(mfrow=c(2,2))
> hist(Temperature)
> boxplot(Temperature, horizontal=TRUE)
> hist(Ozone)
> boxplot(Ozone, horizontal=TRUE)
Creating Multi Panel Plots

The boxplots and barplots are created in single window basically creating a multi panel plots.

Same plot with a change of dimensions in par function would look as follows −


par(mfcol = c(2, 2))
Boxplots and Barplots Advertisements