# Ternary Plots: Setup & Plotting

**URL:** <https://stemaway.com/t/ternary-plots-setup-plotting/84>\
**Category:** Technical Resources\
**Created:** [September 1, 2019, 4:03am UTC](https://stemaway.com/t/ternary-plots-setup-plotting/84 "2019-09-01T04:03:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoori](https://d2nat51eddc6b4.cloudfront.net/user_avatar/stemaway.com/anoori/32/275_2.png) [@anoori](https://stemaway.com/u/anoori)\
**Post date:** [September 1, 2019, 4:03am UTC](https://stemaway.com/t/ternary-plots-setup-plotting/84/1 "2019-09-01T04:03:19Z")

</div>

# Ternary Plots

### Ayush Noori | EduSTEM Advanced Biology
  

## Background

A ternary plot is a barycentric plot on three variables which sum to a constant. It graphically depicts the ratios of the three variables as positions in an equilateral triangle. In population genetics, it is often called a de Finetti diagram.

Please see the HardyWeinberg package vignette [here](http://ftp.uni-bayreuth.de/math/statlib/R/CRAN/doc/vignettes/HardyWeinberg/HardyWeinberg.pdf).

## Setup

Load the requisite libraries.

```auto
if(!require(HardyWeinberg)){
  install.packages("HardyWeinberg")
  library(HardyWeinberg)
}

```

Set the working directory to where you would like your output data to result.

```auto
dir = "<insert appropriate directory address here>"
setwd(dir)

```

## Plotting

AA, AB, and BB are homozygous dominant, heterozygous, and homozygous recessive respectively (i.e. bi-allelic markers). Each row in the column is a different marker or SNP.

Draw random SNPs from a population that is in Hardy-Weinberg Equilibrium.

```auto
set.seed(123)

m = 100 # number of markers
n = 100 # sample size

dat = HWData(n,m)

out = HWTernaryPlot(dat, 100, region=1, vertex.cex=2, signifcolour=TRUE)

```

In this ternary plot, the center parabola represents the ratio p^2+2pq+p^2, or the Hardy-Weinberg Equilibrium. Red loci differ from the ratio by more than a certain p-value, therefore are considered to NOT be in Hardy-Weinberg Equilibrium.

For more information, please see [Hardy-Weinberg Equilibrium and the Ternary Plot](https://dugi-doc.udg.edu//bitstream/handle/10256/737/GRAFFELMAN_JAN_extended_NEW_16_maig_08.pdf?sequence=4) by Graffelman and Camarena.

  

* * *
  

With these courses, we hope to further our mission to make high-quality STEMX education accessible for all. For questions or support, please feel free to reach out to me at [anooristudent@outlook.com](mailto:anooristudent@outlook.com).

Best Regards,

Ayush Noori

_EduSTEM Boston Chapter Founder_

  

**Resources:**

1. [NCBI PubMed](https://www.ncbi.nlm.nih.gov/pubmed/)

The premier source of past and present medical literature. Most supplemental information in Extensions is available via PubMed. When searching PubMed, be sure to use the “Free full text,” and “Sort by: Best Match” filters to find relevant and accessible results.

1. [RCSB Protein Data Bank (PDB)](https://www.rcsb.org/)

A large database of useful 3D structures of large biological molecules, including proteins and nucleic acids. Use the search bar to find a molecule of interest, which can then be examined using the Web-based 3D viewer.

  

 ![image-edustem](https://d1xykt6w2ydx2s.cloudfront.net/original/1X/ada33f4a9e7ca14e9ade0d9f0f41ecbb627fcf81.jpeg)
