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)
# multiple pages of hue:
d <- expand.grid(hue=c('5YR','7.5YR','10YR'), value=2:8, chroma=1:8)
d$hue <- factor(d$hue, levels=c('5YR','7.5YR','10YR'))
d$color <- with(d, munsell2rgb(hue, value, chroma))
xyplot(value ~ chroma | hue,
main="Common Soil Colors", layout=c(3,1), scales=list(alternating=1),
strip=strip.custom(bg=grey(0.85)),
data=d, as.table=TRUE, subscripts=TRUE, xlab='Chroma', ylab='Value',
panel=function(x, y, subscripts, ...)
{
panel.xyplot(x, y, pch=15, cex=4, col=d$color[subscripts])
}
)
# 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
# you will need the colorspace package for this to work
if(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