Skip to content

Instantly share code, notes, and snippets.

@maptracker
Last active January 19, 2016 18:17
Show Gist options
  • Save maptracker/7023c8bf3176e19a4f28 to your computer and use it in GitHub Desktop.
Save maptracker/7023c8bf3176e19a4f28 to your computer and use it in GitHub Desktop.
#color defaults used in #R
### Explore the colors used by R, as hex codes
## The default palette, a vector of strings (like "green2")
myPal <- palette()
## Find the RGB codes for the palette, a red/blue/green matrix of 0-255:
myRGB <- col2rgb( myPal )
## Convert to hex codes:
myHex <- apply( myRGB, 2, function (x) {
rgb(x[1], x[2], x[3], maxColorValue = 255)
} )
myHex
## Lattice has a LOT of arcane color settings
library(lattice)
latVars <- matrix( ncol = 2, byrow = TRUE, data =
c("strip.background", "Light pastels used for conditioning variable bg",
"strip.shingle", "Brighter versions of the strip background",
"strip.border", "Strip border, default all black",
## 'superpose'?? Yikes.
## These are colors used when 2+ groups are "superposed" in one panel
"superpose.line", "Default line colors",
"superpose.symbol", "Default symbol colors",
"superpose.polygon", "? Suggestions on web this is used for legend colors?",
"regions", "Unsure of the utility, it appears to be a red-yellow gradient"
))
## The settings are organized as lists, generally with "col" but
## sometimes with "alpha" and "fill". I am ignoring alpha, it looks
## like it's generally 1
subParams <- c("col", "fill")
apply(latVars, 1, function (x) {
param <- x[1]
desc <- x[2]
print(paste(param, desc, sep = ' : '))
vapply(subParams, function(sp) {
vals <- trellis.par.get(param)[[sp]]
if (!is.null(vals))
print(paste(sprintf("%s:",sp), paste(vals, collapse = ' ')))
""
}, c(""))
cat("\n")
TRUE
})
## This is a built-in lattice function that generates some nice thumbnails,
## including some of the colors shown above
show.settings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment