Hands-on Exercise 9 Part I - Building Ternary Plot with R
Author
Ke Ke
Published
June 10, 2024
Modified
June 27, 2024
Learning Objectives:
Build ternary plot programmatically for visualising and analysing population structure of Singapore.
Getting Started
Ternary plots are a way of displaying the distribution and variability of three-part compositional data. (For example, the proportion of aged, economy active and young population or sand, silt, and clay in soil.) It’s display is a triangle with sides scaled from 0 to 1. Each side represents one of the three components. A point is plotted so that a line drawn perpendicular from the point to each leg of the triangle intersect at the component values of the point.
ggtern, a ggplot extension specially designed to plot ternary diagrams. The package will be used to plot static ternary plots.
Plotly R, an R package for creating interactive web-based graphs via plotly’s JavaScript graphing library, plotly.js . The plotly R libary contains the ggplotly function, which will convert ggplot2 figures into a Plotly object.
Note: Version 3.2.1 of ggplot2 will be installed instead of the latest version of ggplot2. This is because the current version of ggtern package is not compatible to the latest version of ggplot2.
Code chunk below will be used to check if these packages have been installed and also will load them into the working R environment.
pacman::p_load(plotly, ggtern, tidyverse)
package 'DEoptimR' successfully unpacked and MD5 sums checked
package 'tensorA' successfully unpacked and MD5 sums checked
package 'robustbase' successfully unpacked and MD5 sums checked
package 'bayesm' successfully unpacked and MD5 sums checked
package 'compositions' successfully unpacked and MD5 sums checked
package 'latex2exp' successfully unpacked and MD5 sums checked
package 'proto' successfully unpacked and MD5 sums checked
package 'hexbin' successfully unpacked and MD5 sums checked
package 'ggtern' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\idrin\AppData\Local\Temp\RtmpMx0Yjn\downloaded_packages