Heat colors in R utilize basic color ramp functions. Simple example scripts with basic control options follow.
Heat Colors
The heat.colors() function creates a ramp of contiguous colors clustered around the color orange in the red spectrum of the RGB scale. The function has the form heat.colors(num_colors, alpha=value).
Color Ramp Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Configure graphical device par(mai = c(0.3, 0, 0.3, 0), bg = "grey85") h.grid <- layout(matrix(c(1, 2, 3, 4, 5), nrow = 5)) h.count <- c(3, 6, 12, 24, 48) # Plot creation for(i in 5:1){ h.ramp <- heat.colors(h.count[i]) barplot(rep(2, h.count[i]), axes = FALSE, space = 0, col = h.ramp, main = paste0("n = ", h.count[i])) } # Reset graphical device to default values par(op) |
Alpha Transparency
Heat color transparency is controlled with the optional alpha argument. The default value is alpha=1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# Iterate alpha values for n=12 # Configure graphical device par(mai = c(0.3, 0, 0.3, 0), bg = "grey85") h.grid <- layout(matrix(c(1, 2, 3, 4, 5), nrow = 5)) h.alpha <- c(1, 0.75, 0.5, 0.25, 0) # Plot creation for(i in 1:5){ h.ramp <- heat.colors(12, alpha=h.alpha[i]) plot(c(0, 12), c(0,2), bg = "white", type = "n", bty = "n", xaxt = "n", yaxt = "n", xlab = "", ylab = "") rect(0, 0.5, 12, 1.5, col = "navy") barplot(rep(2, 12), axes = FALSE, space = 0, col = h.ramp, add = TRUE, main = paste0("alpha = ", h.alpha[i])) } # Reset graphical device to default values par(op) |