StatFas.com

How to Make a Ternary Plot in StatFas, SPSS, R, Python and Other Tools

By StatFas · Updated 2026-11-09

This tutorial draws a ternary plot and tests group differences with PERMANOVA on Aitchison distance. The example table has a group column (Healthy, IBD, Obese) and three non-negative columns: firmicutes, bacteroidetes and other.

Open the free Ternary Plot GeneratorRead the full guide

What you will make

A publication-ready ternary plot with the compulsory checks and statistics that go with it, produced in five ways. The StatFas generator needs no coding and no account to run; the code versions are for readers who want a scripted workflow. For the theory behind the plot and how to read it, see the full guide.

Example data

ColumnContents
groupHealthy, IBD or Obese (optional)
firmicutesComponent A
bacteroidetesComponent B
otherComponent C

Save your table as ternary.csv with a header row. The StatFas generator has a Load Example Data button with simulated data, so you can follow along without your own file. The example data are invented for illustration and are not real findings.

Method 1: StatFas (free, no coding)

  1. Open the Ternary Plot Generator and click Load Example Data, or paste/upload your own file.
  2. Select the three component columns and the group column. Keep Compositional centre per group and 95% log-ratio ellipses ticked if you want them.
  3. Run the analysis. Read the group centres, descriptive statistics and the PERMANOVA table with its interpretation.
  4. Change colors, fonts, gridlines, line widths and sizes in the figure style panel.
  5. Log in (free) to download the figure (PNG or SVG), tables (CSV) and the Word report.
Analysis needs no login. Downloads of figures, tables and Word reports need a free StatFas account.

Method 2: SPSS

SPSS has no ternary chart. You can run the group comparison on log-ratio coordinates, but you have to compute them yourself. Compute two ilr coordinates and test them with a MANOVA (Analyze > General Linear Model > Multivariate); for a permutation test use R, Python or StatFas.

COMPUTE ilr1 = (1/SQRT(2)) * LN(firmicutes / bacteroidetes).
COMPUTE ilr2 = (1/SQRT(6)) * LN(firmicutes * bacteroidetes / (other * other)).
EXECUTE.

GLM ilr1 ilr2 BY group /PRINT=DESCRIPTIVE.

Check that no component is zero before taking logs. Draw the triangle in another tool.

Method 3: R

library(ggtern); library(compositions); library(vegan)
df <- read.csv("ternary.csv")

ggtern(df, aes(firmicutes, bacteroidetes, other, colour = group)) +
  geom_point(size = 2) + theme_bw()
ggsave("ternary.png", width = 6, height = 5, dpi = 300)

comp <- acomp(df[, c("firmicutes", "bacteroidetes", "other")])
ilr_co <- ilr(comp)                                  # Euclidean distance here = Aitchison distance
adonis2(dist(ilr_co) ~ group, data = df, permutations = 9999)

Packages: install.packages(c("ggtern","compositions","vegan")). adonis2 reports pseudo-F, R² and the permutation p-value.

Method 4: Python

import numpy as np, pandas as pd, plotly.express as px

df = pd.read_csv("ternary.csv")                  # group + three non-negative parts
parts = ["firmicutes", "bacteroidetes", "other"]
df[parts] = df[parts].div(df[parts].sum(axis=1), axis=0) * 100          # close to 100 %
px.scatter_ternary(df, a=parts[0], b=parts[1], c=parts[2], color="group").write_html("ternary.html")

# ilr coordinates and PERMANOVA on Aitchison distance (permutation test)
x = df[parts].values / 100; l = np.log(x); clr = l - l.mean(axis=1, keepdims=True)
H = np.array([[1/np.sqrt(2), -1/np.sqrt(2), 0], [1/np.sqrt(6), 1/np.sqrt(6), -2/np.sqrt(6)]])
ilr = clr @ H.T
g = df["group"].values

def pseudo_f(y, lab):
    n, k = len(y), len(set(lab)); grand = y.mean(0)
    ssb = sum((lab == c).sum() * ((y[lab == c].mean(0) - grand) ** 2).sum() for c in set(lab))
    ssw = sum(((y[lab == c] - y[lab == c].mean(0)) ** 2).sum() for c in set(lab))
    return (ssb / (k - 1)) / (ssw / (n - k)), ssb / (ssb + ssw)

F, r2 = pseudo_f(ilr, g); rng = np.random.default_rng(1)
perm = [pseudo_f(ilr, rng.permutation(g))[0] for _ in range(9999)]
print(f"pseudo-F = {F:.2f}, R2 = {r2:.3f}, p = {(1 + sum(f >= F for f in perm)) / 10000:.4f}")

Requires numpy, pandas and plotly. The script writes an interactive ternary.html; use fig.write_image (needs kaleido) for a PNG. The package python-ternary gives matplotlib ternary axes.

Method 5: MATLAB, OriginPro, Excel and others

OriginPro

Plot > Ternary (menu names vary by version) draws ternary plots from three columns and supports contour and symbol options.

Excel

Excel has no ternary chart. Use a ternary add-in or an XY scatter chart with the coordinates x = 0.5 × (2B + C)/(A + B + C) and y = (√3/2) × C/(A + B + C), then draw the triangle outline manually.

Which method should you choose?

ToolCost and skillTernary plotCompositional statisticsReport-ready output
StatFasFree, in the browserYes (centres, ellipses)Log-ratio centres, PERMANOVAYes, to Word
SPSSLicence neededNoMANOVA on ilr by handTables only
RFree, codingYes (ggtern)compositions, veganManual
PythonFree, codingYes (plotly)ManualManual

Choose StatFas for speed and APA7-ready output, SPSS if your department already licenses it and you only need the statistics, and R or Python when the analysis must be scripted and reproduced in a pipeline.

How to report the result in APA7

Describe how the data were closed to 100%, the transformation (ilr), the distance (Aitchison), the test (PERMANOVA) and the number of permutations, then report pseudo-F with degrees of freedom, R² and p. StatFas writes this paragraph and the tables for you.

See the guide for an example paragraph.

Troubleshooting

Frequently asked questions

Can SPSS make a ternary plot?

No. SPSS has no ternary chart; use StatFas, R, Python or OriginPro.

Is a ternary plot only for three variables?

Yes. For more parts, combine them into three groups or use PCA on log-ratio transformed data.

Try it now. Run the analysis in your browser with the free Ternary Plot Generator. No account is needed to analyze; a free StatFas account is needed only to download figures, tables and the Word report.

Related tools, guides and tutorials

References

  1. Aitchison, J. (1986). The statistical analysis of compositional data. Chapman & Hall.
  2. American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.).
  3. Anderson, M. J. (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecology, 26(1), 32–46.
  4. Egozcue, J. J., Pawlowsky-Glahn, V., Mateu-Figueras, G., & Barceló-Vidal, C. (2003). Isometric logratio transformations for compositional data analysis. Mathematical Geology, 35(3), 279–300.