Figure 13-2: Plot Regions

Portfolio Categories: All Graphics and SGR Book Graphics.

R Graphics Plot Regions

Identification of R Graphics Plot Regions


# 13.3 The plot layout ==================================================== 13.3
# The plot area and margins

myX = seq(1:10)                        # Some x values
myY = c(1, 3, 2, 2, 4, 8, 7, 1, 8, 10) # Some y values

# Plot, region, and device areas

png(filename = "illustrations/fig-13-2-plot regions-BW.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

par(omi = c(.5, .5, .5, .5),           # Set outer margin at .5 inches
  mai = c(.8, .8, .8, .8),             # Set inner margin btwn figure & plot
  fin = c(4.5, 2.5))                   # Set the plot at 4.5 x 2.5 inches

plot(myX, myY)                         # Start new plot in device window
box("outer",                           # Create a box on outer margin
  col = "darkgray", lwd = 6)           #   with a thick dark gray line
box("inner", col = "black", lty = 2)   # Dashed line for figure region (inner)
box("figure", col = "black", lwd = 4)  # Black line for figure region (figure)
box("plot", col = "black")             # Thin black line for plot region (plot)
mtext('Device Region: omi = .5"',      # Put text in margin of device region
  line = 1, outer = TRUE)              #   indicating the outer margin
mtext('Figure Region: mai = .8"',      # Put text in the figure margin
  line = 2)                            #   on the 2nd line
text(x = 5, y = 5, "Plot Region")      # Place text in center of plot region

dev.off()                              # Output png file