require(graphics)
# The Foley and Van Dam PhD Data.
csd <- matrix(c( 4,2,4,6, 4,3,1,4, 4,7,7,1,
0,7,3,2, 4,5,3,2, 5,4,2,2,
3,1,3,0, 4,4,6,7, 1,10,8,7,
1,5,3,2, 1,5,2,1, 4,1,4,3,
0,3,0,6, 2,1,5,5), nrow = 4)
csphd <- function(colors)
barplot(csd, col = colors, ylim = c(0,30),
names = 72:85, xlab = "Year", ylab = "Students",
legend = c("Winter", "Spring", "Summer", "Fall"),
main = "Computer Science PhD Graduates", las = 1)
# The Original (Metaphorical) Colors (Ouch!)
csphd(c("blue", "green", "yellow", "orange"))
# A Color Tetrad (Maximal Color Differences)
csphd(hcl(h = c(30, 120, 210, 300)))
# Same, but lighter and less colorful
# Turn off automatic correction to make sure
# that we have defined real colors.
csphd(hcl(h = c(30, 120, 210, 300),
c = 20, l = 90, fixup = FALSE))
# Analogous Colors
# Good for those with red/green color confusion
csphd(hcl(h = seq(60, 240, by = 60)))
# Metaphorical Colors
csphd(hcl(h = seq(210, 60, length = 4)))
# Cool Colors
csphd(hcl(h = seq(120, 0, length = 4) + 150))
# Warm Colors
csphd(hcl(h = seq(120, 0, length = 4) - 30))
# Single Color
hist(stats::rnorm(1000), col = hcl(240))
## Exploring the hcl() color space {in its mapping to R's sRGB colors}:
demo(hclColors)
Run the code above in your browser using DataLab