I am trying to reproduce the USDA Soil Triangle. To do so, I would need to flip the x and y axis of the default pgfplots-ternary.

I understand, that I could switch my inputs (don't really want to do that), but I would need to change the directions as well, and I not even having any success with that.

In the default ternary axis, the y axis is on the left and the x axis is on the right, and x runs from 0 (bottom right) to 100 (top) and y runs from top to bottom left. However, according to the USDA Soil Triangle, x needs to run from bottom left to top, y needs to run from top to bottom right, and z from bottom right to bottom left.

Also, the x axis (and ticks) need to be horizontal (parallel to z), whereas y needs to be parallel to x and z should be parallel to y.

I tried the x dir=reverse and axis on top commands, as I thought I could simply flip my coordinates, but I had no luck. Did anybody ever have a similar problem or knows an answer to this?

(enter image description here)

I did what I could to at least have all the data and such. Here is what I got:


\usepackage[dvipsnames]{xcolor} % color handling
\usepackage{tikz}                   % draw pictures and diagrams
\usepackage{pgfplots}            % proper plotting
\usepackage{file contents}     % writing reading of data files
\usepgfplotslibrary{ternary, units}

Loamy Sand,0,15,85
Loamy Sand,10,0,90
Loamy Sand,15,0,85
Loamy Sand,0,30,70
Sandy Clay,35,0,65
Sandy Clay,55,0,45
Sandy Clay,35,20,45
Silty Clay,40,40,20
Silty Clay,60,40,0
Silty Clay,40,60,0
Sandy Loam,0,30,70
Sandy Loam,15,0,85
Sandy Loam,20,0,80
Sandy Loam,20,27,53
Sandy Loam,8,40,52
Sandy Loam,8,50,42
Sandy Loam,0,50,50
Clay Loam,27,28,45
Clay Loam,40,15,45
Clay Loam,40,40,20
Clay Loam,27,53,20
Sandy Clay Loam,20,0,80
Sandy Clay Loam,35,0,65
Sandy Clay Loam,35,20,45
Sandy Clay Loam,27,28,45
Sandy Clay Loam,20,27,53
Silty Loam,0,50,50
Silty Loam,27,50,23
Silty Loam,27,73,0
Silty Loam,13,87,0
Silty Loam,13,80,7
Silty Loam,0,80,20
Silty Clay Loam,27,53,20
Silty Clay Loam,40,40,20
Silty Clay Loam,40,60,0
Silty Clay Loam,27,73,0

    discard if not/.style 2 args={
        x filter/.code={


ternary limits relative,
xlabel=x (Clay),
ylabel=y (Silt),
zlabel=z (Sand),
minor tick num=1,
% Sands
\addplot3  [fill=yellow, fill opacity=\myopacity, discard if not={name}{Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3  [fill=Melon, fill opacity=\myopacity,discard if not={name}{Loamy Sand}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Sand Text
\node at (axis cs:3,5,) {\tiny Sand};
\node at (axis cs:5,13) {\tiny Loamy};
\node at (axis cs:2,18) {\tiny Sand};

% Clays 
\addplot3 [fill=yellow, fill opacity=\myopacity, discard if not={name}{Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=red, fill opacity=\myopacity, discard if not={name}{Sandy Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Aquamarine!50, fill opacity=\myopacity, discard if not={name}{Silty Clay}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
%Clay Text
\node at (axis cs:65,16) {\tiny Clay};
\node at (axis cs:43,6) {\tiny Sandy};
\node at (axis cs:38,8) {\tiny Clay};
\node at (axis cs:48,47) {\tiny Silty};
\node at (axis cs:44,49) {\tiny Clay};

% Loams
\addplot3 [fill=brown, fill opacity=\myopacity, discard if not={name}{Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=purple!50, fill opacity=\myopacity, discard if not={name}{Sandy Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=purple!25, fill opacity=\myopacity, discard if not={name}{Sandy Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=SpringGreen, fill opacity=\myopacity, discard if not={name}{Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Green, fill opacity=\myopacity, discard if not={name}{Silty Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
\addplot3 [fill=Aquamarine, fill opacity=\myopacity, discard if not={name}{Silty Clay Loam}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Loams Text
\node at (axis cs:19,40) {\tiny Loam};
\node at (axis cs:12,23) {\tiny Sandy Loam};
\node at (axis cs:28,13) {\tiny Sandy Clay Loam};
\node at (axis cs:33,35) {\tiny Clay Loam};
\node at (axis cs:13,65) {\tiny Silty Loam};
\node at (axis cs:36,55) {\tiny Silty};
\node at (axis cs:31,58) {\tiny Clay Loam};

% Silts
\addplot3 [fill=green, fill opacity=\myopacity, discard if not={name}{Silt}] table [x=clay,y=silt,z=sand, col sep=comma] {USDASoils.csv};
% Silt Text
\node at (axis cs:6,88) {\tiny Silt};


Which looks like this: enter image description here

I am considerably happy with my result, but I would like to:

1) Switch the axis (as explained above),

2) Remove the minor ticks (but keep the minor grid - I could not get that to work), and

3) have the axis labels sloped along the triangle sides (as in the original picture above)

  • Where is the code that produces this or hopefully a simpler one?
    – percusse
    Jul 18, 2014 at 6:30
  • I did not get anywhere further then whats posted in the pgfplots manual. So I did not add the code here to not be redundant. But I can post it below. @percusse
    – Raphael
    Jul 18, 2014 at 6:37
  • @percusse I finished the coding and added it above. Hopefully that will help. Thanks for your interest.
    – Raphael
    Jul 18, 2014 at 23:25
  • 1
    @percusse Do you think there is still hope for an answer?
    – Raphael
    Aug 20, 2014 at 0:11
  • For the record: I added a feature request for that some time ago to the PGFPlots Tracker. Feb 12, 2017 at 18:57


You must log in to answer this question.

Browse other questions tagged .