How to create multiple plots of different sizes in base R?

R ProgrammingServer Side ProgrammingProgramming

Often, we have multiple values, vectors or columns of an R data frame that needs to be plotted on a single graph so that we can compare them at the same time or they have some kind of relationship among them. Therefore, we can use layout function along with matrix function to divide the plot window as shown in the below example

Consider the below layout and plot of individual values −

Example

layout(matrix(c(1,2,3,3,4,5,6,6),nrow=4,ncol=2,byrow=FALSE))
plot(500)
plot(525)
plot(530)
plot(531)
plot(540)
plot(528)

Output

Changing the layout and creating the plots −

Example

layout(matrix(c(1,2,3,3,4,5,6,6),nrow=4,ncol=2,byrow=TRUE))
plot(500)
plot(525)
plot(530)
plot(535)
plot(533)
plot(540)

Output

raja
Published on 19-Oct-2020 18:15:29
Advertisements