- Related Questions & Answers
- How to create boxplot for multiple categories in base R?
- How to create heatmap in base R?
- How to add named vectors of different sizes based on names in R?
- How to create boxplot for multiple categories with long names in base R?
- How to create an arrow in base R?
- How to create two 3d plots at a time in R?
- How to stop par(mfrow) to create multiple plots in one plot window and create only one plot in R?
- How to create side-by-side boxplot in base R?
- How to create boxplot in base R without axes labels?
- How to create two plots using ggplot2 arranged in a vertical manner in R?
- How to create plot in R with different shape of points?
- How to create a contingency table using datasets in base R?
- How to create a horizontal line in a histogram in base R?
- Merge k sorted arrays of different sizes in C++
- How to display a list of plots with the help of grid.arrange in R?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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 −

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)

Changing the layout and creating the plots −

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)

Advertisements