The goal of ggsoiltexture is to provide a simple ggplot function for the plotting of soil textural data. It is still in development, mainly for use in pubs. If you use this package please cite this repository. Hope it is useful!
The code was development based on the ggplot_piper functions written by Jonh Dorian and inspired by the R package ggtern. Thanks for sharing your knowledge.
You can install the ggsoiltexture v1.0 from GitHub with:
# install.packages("devtools")
devtools::install_github("Saryace/ggsoiltexture")Dataframe or tibble with three variables called:
- sand, as percentage
- silt, as percentage
- clay, as percentage
- Visit the lab's YT channel
ggsoiltexture
This function plots soil texture in a ternary plot.
Your data must to sum up 100%. The function will stop if it is not checked previously
library(tidyverse)
library(ggsoiltexture)
fail_data <- data.frame(
clay = c(100,20,25,20,10),
silt = c(35,150,45,30,40),
sand = c(55.65,30,0,500,50))
ggsoiltexture(fail_data)
Error in ggsoiltexture(fail_data) :
Some of your textural data do not sum 100%, please check.!
A simple plot can be done directly
some_data <- data.frame(id = c("A","B","C","D","E"),
clay = c(10,20,25,20,10),
silt = c(35,15,45,30,40),
sand = c(55,65,30,50,50),
om = c(5,15,5,12,7))
another_plot <-
ggsoiltexture(some_data)
another_plotBecause ggsoiltexture is based on ggplot2, more geoms, themes, can be added
pub_plot <-
ggsoiltexture(some_data) +
geom_point(aes(color = om), size = 6) +
scale_color_continuous(type = "viridis") +
labs(color = "Organic\nMatter (%)") +
geom_label_repel(aes(label = id), box.padding = 0.5) +
theme(legend.title = element_text(face = "bold"),
legend.position = "bottom")
pub_plot
Using geom_polygon, a layer showing the USDA classes can be added.
# load the USDA polygon info
data(usda_polygons)
# then plot
usda_plot <-
ggsoiltexture(some_data) +
geom_polygon(
data = usda_polygons,
aes(fill = label),
alpha = 0.0,
size = 0.5,
color = "black"
) +
geom_text(data = usda_polygons %>% group_by(label) %>%
summarise_if(is.numeric, mean, na.rm = TRUE),
aes(label = label),
color = 'black',
size = 3) +
theme(legend.position = "none")


