<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/multipanel-graphics-in-r-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2017/02/02/multipanel-graphics-in-r-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=multipanel-graphics-in-r-part-1"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="http://r-exercises.com/wp-content/uploads/2017/01/unnamed-chunk-1-10.png?x61433"><img sizes="(max-width: 300px) 100vw, 300px" alt="Multipanel Graphics in R" class="wp-image-4155" src="https://i2.wp.com/r-exercises.com/wp-content/uploads/2017/01/unnamed-chunk-1-10-300x300.png?resize=300%2C300" data-recalc-dims="1"></a>In many situations, we require that several plots are placed in the same figure as subplots. R has various ways of doing it. Base Graphics has three different ways to draw subplots, i.e. <code> mfrow</code>, <code>layout</code> and <code>split.screen</code>, with increasing degree of complexity, and, at the same time, with increased control over the plot elements. This example introduces the <code>mfrow</code>,  <code>mfcol</code> and <code>layout</code> functions in Base Graphics. We use the familiar <code>iris</code> dataset for the illustrations.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/02/02/multipanel-graphics-in-r-1/">here</a>.If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p><strong>Exercise 1</strong><br>
Consider the <code>iris</code> dataset, draw the following scatterplots, a) <code>Sepal.Length</code> vs <code>Sepal.Width</code>, b) <code>Sepal.Length </code> vs <code>Petal.Length </code>, and c) <code>Sepal.Length </code> vs <code>Petal.Width </code>. Annotate each scatterplot with a title. Use separate colors and plotting characters for each plot.</p>
<p><strong>Exercise 2</strong><br>
Plot the three scatterplots in the same figure as subplots arranged in one row. Use <code>mfrow</code>.</p>
<p><strong>Exercise 3</strong><br>
Plot the three scatterplots in the same figure as subplots arranged in one column. Use <code>mfrow</code> .</p>
<p><strong>Exercise 4</strong><br>
Repeat the same scatterplots. Partition in such a way that the first row contains plots a and b, and the second row contain plot c. Use <code>mfrow</code>.</p>
<p><strong>Exercise 5</strong><br>
Repeat Exercise 2 with <code>mfcol</code>.</p>
<p><strong>Exercise 6</strong><br>
Repeat Exercise 3 with <code>mfcol</code>.</p>
<p><strong>Exercise 7</strong><br>
Repeat Exercise 4 with <code>mfcol</code>.</p>
<p><strong>Exercise 8</strong><br>
Repeat Exercise 2 with <code>layout</code>.</p>
<p><strong>Exercise 9</strong><br>
Repeat Exercise 3 with <code>layout</code>.</p>
<p><strong>Exercise 10</strong><br>
Repeat Exercise 4 with <code>layout</code>. In this case, let scatterplot c occupy the second row completely.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a title="Advanced Base Graphics Exercises" target="_blank" rel="nofollow" href="http://r-exercises.com/2016/09/23/advanced-base-graphics-exercises/">Advanced Base Graphics Exercises </a></li>
<li><a title="Graphics parameters exercises" target="_blank" rel="nofollow" href="http://r-exercises.com/2016/03/24/graphics-parameters-exercises/">Graphics parameters exercises </a></li>
<li><a title="Getting started with Plotly: basic Plots" target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/10/getting-started-with-plotly-basic-plots/">Getting started with Plotly: basic Plots </a></li>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/start-here-to-learn-r/">Explore all our (>1000) R exercises</a></li>
<li><a target="_blank" rel="nofollow" href="http://r-exercises.com/r-courses/">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2017/02/02/multipanel-graphics-in-r-part-1/?utm_source=rss&utm_medium=rss&utm_campaign=multipanel-graphics-in-r-part-1"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/ULOL5AnqoPc"></a></div>