Figure 15-2c: Color Transparency

Portfolio Categories: All Graphics and SGR Color Graphics.

Adding Transparency to Colors in R Graphics

Adding Transparency to Colors in R Graphics


# 15.1c Color transparency =============================================== 15.1c

png(filename = "illustrations/fig-15-2c-transparency.png",
  units = "in",                        # Set measurements in inches
  res = 1200,                          # Set resolution at 1200dpi
  width = 6,                           # Width at 6 inches
  height = 2)                          # Height at 4 inches

par(mar = c(0, 0, 0, 0))               # Set all margins to 0
plot.new()                             # New plot

abline(h = .5,                         # Add a horizontal line at .5
  lwd = 4)                             # Set line width to 4

segments(                              # Add segments w/ degrees of transparency
  x0 = seq(.1, .9, by = .15),          # The first x values for the lines
  y0 = .1,                             # The first y values for the lines
  x1 = seq(.1, .9, by = .15),          # The second x values
  y1 = .9,                             # The second y values
  col=c("#C0D9AF10","#C0D9AF25",       # Use lichen green w/ increasing opacity
    "#C0D9AF50", "#C0D9AFA5",
    "#C0D9AFD0","#C0D9AFFF"),
  lwd = 40)                            # Line width = 40

text(                                  # Black labels for degree of opacity
  x = seq(.1, .9, by = .15),           # x values
  y = .1,                              # y value
  labels =                             # Text to show alpha channel values
    c("10", "25", "50", "A5", "D0", "FF"))    

dev.off()                              # Output png file