Sometimes you want to show the proportion of items in 3
different states. This is the perfect
use for a ternary diagram. I needed to
do this to show how many taxa had been simulated to have one of 3 possible
character states. Basically the diagram
is triangle and as a point moves towards any of the vertices the proportion of
taxa in that state is increasing. This
type of graph would be incredibly complicated to set up in excel but in R we
can do it in a flash. It comes from the
package VCD if you want the sample data set and the script file that I used they are on dropbox.

I was using this in conjunction with the simulations
described in my last post. And this type
of diagram was actually inspired by its use in a recent paper by Sam Price et
al. The figure is actually back in the
supplemental material but it shows the results of posterior predictive
simulations modeling the number taxa with different types of diets. I am doing something very similar but with
sex chromosomes. One cool opportunity I
haven’t seen people take advantage of is to add another variable in the mix and
color the points by it. For instance in
my example I color coded the data points by the root state used in the simulation. You could use a clustering algorithm on your
trees and then color by the tree cluster that you simulated with. The
possibilities are pretty cool!

require("vcd")

read.table("PPS-data",
header=TRUE)->simresult #This loads
our data from a tab delimited file

attach(simresult)

colors <-
c("black","red","green", "orange") #This sets up a vector of colors

pch <-
substr(levels(Root), 1, 3) #This assigns the colors to the Root states column

ternaryplot( #This is the actual plotting of
our data

simresult[,2:4], #Here I provide the file and columns to plot

pch = 20, #This is choosing the shape of
data points (simple circle here)

cex = .5, #This is the size of the data points

col = colors[as.numeric(Root)], #Telling it to color the points

main = "PPS - 3-State Model" #Provides a title for the
graph

)

grid_legend(0.9,
0.9, pch, colors, levels(Root),title = "Root States") #Sets up a legend

Cheers

I replotted your data using a package that I have written to extend ggplot2 for ternary diagrams. http://ggtern.com/2013/12/16/pps-3-state-model/

ReplyDelete