Example

Required packages.

library(soilDB)
library(aqp)
library(plyr)

Make some example data.

colors <- c('10YR 3/5', '5YR 5/6', '2.5Y 5/6')
weights <- c(60, 30, 10)

# combine into a data.frame and convert to sRGB
x <- cbind(
  parseMunsell(colors, convertColors=FALSE),
  parseMunsell(colors, return_triplets=TRUE),
  pct=weights,
  col=parseMunsell(colors, convertColors=TRUE)
)

x
##    hue value chroma         r         g          b pct       col
## 1 10YR     3      5 0.3817539 0.2599868 0.09323485  60 #614218FF
## 2  5YR     5      6 0.6516906 0.4320947 0.27623886  30 #A66E46FF
## 3 2.5Y     5      6 0.5907267 0.4641984 0.19181078  10 #977631FF

Add required columns for simplifyColorData().

names(x)[1:3] <- paste0('color', names(x)[1:3])
x$id <- 1
x$colormoistst <- "Dry"

# simplify
simplifyColorData(x, id.var='id')
##   id    d_r     d_g     d_b d_hue d_value d_chroma    d_sigma m_r m_g m_b m_hue m_value m_chroma
## 1  1 0.4812 0.33025 0.15697  10YR       4        5 0.02051464  NA  NA  NA  <NA>    <NA>     <NA>
##   m_sigma moist_soil_color dry_soil_color
## 1      NA             <NA>        #7B5428

Demonstrate mixing soil colors in CIE LAB and sRGB color spaces via mix_and_clean_colors().

mixColorDemo <- function(x) {
  x <- x[order(x$pct, decreasing = TRUE), ]
  n.cols <- nrow(x)
  x.vals <- 1:n.cols
  y.vals <- rep(0, times=n.cols)
  cols <- rgb(x[, c('r', 'g', 'b')])
  col.txt <- paste0(x$colorhue, ' ', x$colorvalue , '/', x$colorchroma, '\n(', x$pct, '%)')
  
  plot(x.vals, y.vals, col=cols, pch=15, cex=5, axes=FALSE, ylab='', xlab='', xlim=c(0.5, n.cols + 2.5))
  text(x.vals, y.vals, col.txt, pos=1, offset=1.1, cex=0.75)
  text(x.vals[-length(x.vals)]+0.5, y.vals, '+', cex=2, lwd=2)
  text(max(x.vals)+0.5, y.vals[1], '=', cex=2, lwd=2)
  
  # mix in both color spaces
  mixed.lab <- mix_and_clean_colors(x, colorSpace = 'LAB', backTransform = TRUE)
  mixed.srgb <- mix_and_clean_colors(x, colorSpace = 'sRGB', backTransform = TRUE)
  
  # add mixed colors
  points(max(x.vals)+1, y.vals[1], col=rgb(mixed.lab[, c('r', 'g', 'b')]), cex=5, pch=15)
  col.txt <- paste0(mixed.lab$colorhue, ' ', mixed.lab$colorvalue , '/', mixed.lab$colorchroma, '\n(LAB)')
  text(max(x.vals)+1, y.vals[1], col.txt, pos=1, offset=1.1, cex=0.75)
  
  points(max(x.vals)+1.5, y.vals[2], col=rgb(mixed.srgb[, c('r', 'g', 'b')]), cex=5, pch=15)
  col.txt <- paste0(mixed.srgb$colorhue, ' ', mixed.srgb$colorvalue , '/', mixed.srgb$colorchroma, '\n(sRGB)')
  text(max(x.vals)+1.5, y.vals[1], col.txt, pos=1, offset=1.1, cex=0.75)
}


par(mar=c(1,1,1,1))
mixColorDemo(x)


This document is based on aqp version 1.17 and soilDB version 2.3.6.