Figure 15-7: Line Types

Portfolio Categories: All Graphics and SGR Book Graphics.

Line Types in R Graphics

Line Types in R Graphics


# 15.3 Adding Lines ======================================================= 15.3

png(filename = "illustrations/fig-15-7-line types.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(mai = c(0, 0, 0, 0))               # Set for no margins

plot.new()                             # Start a plot
  
segments(                              # Add segments w/ degrees of transparency
  x0 = .1,                             # The first x values for the lines
  y0 = seq(.9, .1, -.16),              # The first y values for the lines
  x1 = .6,                             # The second x values
  y1 = seq(.9, .1, -.16),              # The second y values
  lty = c(1:6),                        # A vector of line types
  lwd = 2)                             # Line width = 2


text(                                  # Add labels 
  x = .65,                             # x values
  y = seq(.9, .1, -.16),               # y value
  pos = 4,                             # Text to right of point
  cex = 1.25,                          # Text size
  label = c("lty = 1 or 'solid'",      # The set of labels
    "lty = 2 or 'dashed'",             
    "lty = 3 or 'dotted'",
    "lty = 4 or 'dotdash'",
    "lty = 5 or 'longdash'",
    "lty = 6 or 'twodash'"))
 
dev.off()                              # Output png file