2D Posterior Density Plots in R

I have been grappling with visualizing two dimensional histograms of posterior density distributions of parameters, as estimated by one of your favorite programs – IMa2, MIGRATE-n, MSVAR, etc. All these programs print out distributions of estimated parameters, and here’s a neat and innovative way to visualize them in two dimensions. As an example, I used the output of MSVAR v.1.3 for some simulated microsatellite data with a bottleneck – that can be accessed at this link.

A little Googling led me to this great post on five different ways to build two dimensional histograms in R – I use the hexbinplot() function here to obtain my plots. Feel free to play around with the other methods, and program outputs!

install.packages(“hexbin”)
install.packages(“RColorBrewer”)
library(hexbin)
library(RColorBrewer)

rf <- colorRampPalette(rev(brewer.pal(11,'Spectral')))
r <- rf(32)
hpars <- read.table("hpars.dat")
hexbinplot(V6~V4,data=hpars,xlab="Log10(Current population size N0)",
ylab="Log10(Past population size Na)",colramp=rf)
2D density plot of estimated ancestral and current population sizes using MSVAR.
2D density plot of estimated ancestral and current population sizes using MSVAR.

And voila! Simple, yet fun and intuitive visualization of densities!

This entry was posted in bioinformatics, howto, population genetics, R, software and tagged , , , . Bookmark the permalink.