Figure 13-7: The Layout Method

Portfolio Categories: All Graphics and SGR Book Graphics.

Demonstration of layout method grid in R graphics

The Layout Method for Placing Multiple PLots


# The layout Function ==========================================================
# Some simple examples
layout(matrix(c(1:4), ncol = 2))       # A simple 2x2 grid using layout
layout.show(4)                         # Show the resulting grid

png(filename = "illustrations/fig-13-7-layout method.png",
  units = "in",                        # Set measurements in inches
  res = 1200,                          # Set resolution at 1200dpi
  width = 6,                           # Width at 6 inches
  height = 4)                          # Height at 4 inches

layout(                                # Setup a multiplot layout
  matrix(c(1:15),                      # Create a matrix of 15 cells
    ncol = 3,                          #   in 3 columns (5 rows of 3 cells)
    byrow = T),                        # Order the cells by row
  heights = c(2, 2, .5, .5, 1))        # Set row heights

layout.show(15)                        # Show the layout grid

dev.off()                              # Output png file