# drawing surface plots on the IR³ simplex

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Xi'an's Og » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**A**s a result of a corridor conversation in Warwick, I started looking at distributions on the IR³ simplex,

and wanted to plot the density in a nice way. As I could not find a proper package on CRAN, the closer being the BMAmevt (for *Bayesian Model Averaging for Multivariate Extremes*) R package developed by a former TSI Master student, Anne Sabourin, I ended up programming the thing myself. And producing the picture above. Here is the code, for all it is worth:

# setting the limits par(mar=c(0,0,0,0),bg="black") plot(c(0,1),col="white",axes=F,xlab="",ylab="", xlim=c(-1,1)*1.1/sqrt(2),ylim=c(-.1,sqrt(3/2))*1.1) # density on a grid with NAs outside, as in image() gride=matrix(NA,ncol=520,nrow=520) ww3=ww2=seq(.01,.99,le=520) for (i in 1:520){ cur=ww2[i];op=1-cur for (j in 1:(521-i)) gride[i,j]=mydensity(c(cur,ww3[j],op-ww3[j])) } # preparing the graph subset=(1:length(gride))[!is.na(gride)] logride=log(gride[subset]) grida=(logride-min(logride))/diff(range(logride)) grolor=terrain.colors(250)[1+trunc(as.vector(grida)*250)] iis=(subset%%520)+520*(subset==520) jis=(subset%/%520)+1 # plotting the value of the (log-)density # at each point of the grid points(x=(ww3[jis]-ww2[iis])/sqrt(2), y=(1-ww3[jis]-ww2[iis])/sqrt(2/3), pch=20,col=grolor,cex=.3)

Filed under: pictures, R, Statistics, University life Tagged: Bayesian inference, image(), posterior distribution, R, simplex, surface, terrain.colors()

To

**leave a comment**for the author, please follow the link and comment on their blog:**Xi'an's Og » R**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.