Session Ready
Exercise

Constructing and displaying layout matrices

The video illustrated how to set up a layout matrix to be used with the layout() function in creating a plot array. You can think of the layout matrix as the plot pane, where a 0 represents empty space and other numbers represent the plot number, which is determined by the sequence of visualization function calls. For example, a 1 in the layout matrix refers to the visualization that was first called, a 2 refers to the plot of the second visualization call, etc. This exercise asks you to create your own 3 x 2 layout matrix, using the c() function to concatenate numbers into vectors that will form the rows of the matrix.

You will then use the matrix() function to convert these rows into a matrix and apply the layout() function to set up the desired plot array. The convenience function layout.show() can then be used to verify that the plot array has the shape you want.

As reference, feel free to use the slides from the video, which you can access by clicking on the "Slides" tab next to the "R Console" tab. Pay close attention to the example layout matrix and the resulting plot array.

Instructions
100 XP
  • Using the matrix() function, create a matrix called layoutMatrix with three rows and two columns:
    • the first row designates an empty plot to the left and plot 1 to the right.
    • the second row designates plot 2 to the left and an empty plot to the right.
    • the third row designates an empty plot to the left and plot 3 to the right.
  • Use the layout() function to set up the desired plot array.
  • Use the layout.show() function to show the arrangement of all three plots.