Figure: 15-6: Drawing Symbols

Portfolio Categories: All Graphics and SGR Book Graphics.

Drawing with Symbols in R Graphics

Drawing with Symbols in R Graphics


# 15.2b The symbols() approach =========================================== 15.2b
                                       # Output a png file
png(filename = "illustrations/fig-15-6-symbols-BW.png",
  units = "in",                        # Set measurements in inches
  res = 1200,                          # Set resolution at 1200dpi
  width = 6,                           # Width at 6 inches
  height = 4)                          # Height at 6 inches

par(mai = c(1, 1, .25, .25))

symbols(x = c(1:3), y = c(2, 4, 3),    # Set up some X and Y values
  circles = c(1, 2, 1.5),              # Circle radii
  bg = gray.colors(3),                 # Circle colors from gray palette
  xlim = c(0,5), ylim = c(0,5),        # Set range of plot
  xlab = "X", ylab = "Y")              # Set axis labels

myRect = rbind(c(1.5, .75),            # Set widths for 2 rectangles
  c(.75, 2))                           # Set heights for 2 rectangles

symbols(x = c(2, 4), y = c(2, 3),      # 2nd symbol plot X & Y coords
  add = TRUE,                          # Overlay on previous plot     
  rectangles = myRect,                 # Add rectangles
  bg = c("lightgray", "darkgray"))     # Rectangle colors      

dev.off()                              # Close png device to output plot