0

I am trying to plot a soil profile in R using the package aqp: algorithms for quantitative pedology. The profile should represent matrix colour, plus mottling colour and percentage. For that purpose, I am using the function addVolumeFraction, which works well to some extent: it plots points on the profile that correspond to the right mottling percentage for each horizon, but it doesn't assign the corresponding colours. Here an example:

#Variables for the soil profile
id <- rep(1, 4)
hor <- c("H1", "H2", "H3", "H4")
tops <- c(0,15,35,60)
bottoms <- c(15, 35, 60, 95)
mx_Hex <- c("#695F59FF", "#A59181FF", "#9E9388FF", "#A59181FF")
mot_Hex <- c("#EEB422","#EEB422", "#CD4F39", "#CD4F39")
mot_perc <- c(5, 10, 40, 8)

#Soil profile df
soildf <- data.frame(id,hor,tops,bottoms, mx_Hex, mot_Hex, mot_perc)
soildf$mx_Hex <- as.character(mx_Hex) #the class "SoilProfileCollection" needs colors as characters
soildf$mot_Hex <- as.character(mot_Hex)

# Transform df to "SoilProfileCollection"
depths(soildf) <- id ~ tops + bottoms

#Plot
plot(soildf, name = "hor", color = "mx_Hex", divide.hz = TRUE)
addVolumeFraction(soildf, "mot_perc",pch = 19, cex.min = 0.4, cex.max = 0.5, col = soildf$mot_Hex)

Soil profile plot

As you can see on the plot, the mottles' colours are mixed along the profile. I would like to have mottles of a given colour for their corresponding horizon instead. Can anybody help me to solve this problem?

Thanks!!

Carlos G
  • 19
  • 2

1 Answers1

0

This works as expected in the current version of aqp available on CRAN (v1.19 released in January 2020).

I modified your example below to use alternating black and white mottles in each horizon.

library(aqp)

#Variables for the soil profile
id <- rep(1, 4)
hor <- c("H1", "H2", "H3", "H4")
tops <- c(0,15,35,60)
bottoms <- c(15, 35, 60, 95)
mx_Hex <- c("#695F59FF", "#A59181FF", "#9E9388FF", "#A59181FF")

# change mottle colors to something obviously different in each horizon
mot_Hex <- c("#FFFFFF", "#000000", "#FFFFFF","#000000")
mot_perc <- c(5, 10, 40, 8)

#Soil profile df
soildf <- data.frame(id, hor, tops, bottoms, mx_Hex, mot_Hex, mot_perc)

#the class "SoilProfileCollection" needs colors as characters
soildf$mx_Hex <- as.character(mx_Hex) 
soildf$mot_Hex <- as.character(mot_Hex)

# Transform df to "SoilProfileCollection"
depths(soildf) <- id ~ tops + bottoms

#Plot
plot(soildf,
     name = "hor",
     color = "mx_Hex",
     divide.hz = TRUE)

addVolumeFraction(
  soildf,
  "mot_perc",
  pch = 19,
  cex.min = 0.4,
  cex.max = 0.5,
  col = soildf$mot_Hex
)

alternating mottles

Andrew Brown
  • 1,045
  • 6
  • 13