Learn R Programming

aqp (version 0.85)

munsell2rgb: Convert Munsell Notation to RGB

Description

Color conversion based on a look-up table of common soil colors.

Usage

munsell2rgb(the_hue, the_value, the_chroma, alpha=1, 
maxColorValue=1, return_triplets=FALSE)

Arguments

the_hue
a vector of one or more more hues, upper-case
the_value
a vector of one or more values
the_chroma
a vector of one or more chromas
alpha
alpha channel value (for transparency effects)
maxColorValue
maximum RGB color value (seergb)
return_triplets
should the function return raw RGB triplets instead of an R color

Value

  • A vector of R colors is returned that is the same length as the input data. If return_triplets is TRUE, then a dataframe (of sample length as input) of r,g,b values is returned.

Details

This function generalizes to vectorized usage, as long as the lenght of each argument is the same.

References

http://casoilresource.lawr.ucdavis.edu/drupal/node/201

Examples

Run this code
library(aqp)

# basic example:
d <- expand.grid(hue='10YR', value=2:8, chroma=1:8)
d$color <- with(d, munsell2rgb(hue, value, chroma))

# similar to the 10YR color book page
plot(value ~ chroma, data=d, col=d$color, pch=15, cex=3)


# soils example
data(sp1)

# convert colors
sp1$soil_color <- with(sp1, munsell2rgb(hue, value, chroma))

# simple plot, may need to tweak gamma-correction...
image(matrix(1:nrow(sp1)), axes=FALSE, col=sp1$soil_color, main='Soil Colors')

# convert into a more useful color space
require(colorspace)

# keep RGB triplets from conversion
sp1.rgb <- with(sp1, munsell2rgb(hue, value, chroma, return_triplets=TRUE))

# convert into LAB color space
sp1.lab <- as(with(sp1.rgb, RGB(r,g,b)), 'LAB')
plot(sp1.lab)

Run the code above in your browser using DataLab