# Flip x and y axis of ternary graph

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?

()

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

\documentclass[]{standalone}

\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}

\begin{filecontents*}{USDASoils.csv}
name,clay,silt,sand
Sand,0,0,100
Sand,10,0,90
Sand,0,15,85
Loamy Sand,0,15,85
Loamy Sand,10,0,90
Loamy Sand,15,0,85
Loamy Sand,0,30,70
Clay,55,0,45
Clay,100,0,0
Clay,60,40,0
Clay,40,40,20
Clay,40,15,45
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
Loam,8,40,52
Loam,20,27,53
Loam,27,28,45
Loam,27,50,23
Loam,8,50,42
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
Silt,0,80,20
Silt,13,80,7
Silt,13,87,0
Silt,0,100,0
\end{filecontents*}

\pgfplotsset{
x filter/.code={
\edef\tempa{\thisrow{#1}}
\edef\tempb{#2}
\ifx\tempa\tempb
\else
\def\pgfmathresult{inf}
\fi
}
}
}

\begin{document}

\begin{tikzpicture}[scale=0.9]
\begin{ternaryaxis}[
xmax=100,
ymax=100,
zmax=100,
ternary limits relative,
xlabel=x (Clay),
ylabel=y (Silt),
zlabel=z (Sand),
xtick={0,10,...,100},
ytick={0,10,...,100},
ztick={0,10,...,100},
minor tick num=1,
grid=both,
]
\def\myopacity{0.5}
% 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};
\end{ternaryaxis}
\end{tikzpicture}

\end{document}


Which looks like this:

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 '14 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 '14 at 6:37
• @percusse I finished the coding and added it above. Hopefully that will help. Thanks for your interest. – Raphael Jul 18 '14 at 23:25
• @percusse Do you think there is still hope for an answer? – Raphael Aug 20 '14 at 0:11
• For the record: I added a feature request for that some time ago to the PGFPlots Tracker. – Stefan Pinnow Feb 12 '17 at 18:57