Wednesday, April 5, 2023

Some details on making a figure (preserving trailing zeros, multi-panel configuration, etc.)

For a tweet about a recent post to this blog, I created a multipanel figure with some interesting attributes (differing panel heights, preserving trailing digits in figure labels using sprintf) that I thought might be worth preserving for posterity (both for my benefit & that of readers).

First, here’s the tweet:

Now here’s how the sausage was made.

layout(matrix(c(1,1,2,3),2,2,byrow=TRUE),height=c(0.6,0.4))
plotTree(squamate.tree,ftype="off",lwd=1,offset=2,
  type="fan",part=0.5,mar=c(0.1,0.1,2.1,0.1))
mtext("a) digit number in squamates",line=0,adj=0.05)
tiplabels(pie=ard_fit1$data[squamate.tree$tip.label,],
  piecol=viridisLite::viridis(n=6),cex=0.3)
legend("topright",legend=paste(0:5,"digit(s)"),pch=21,
  pt.bg=viridisLite::viridis(n=6),pt.cex=1.5,bty="n")
plot(ard_fit1,width=TRUE,text=FALSE,color=TRUE,
  show.zeros=FALSE,max.lwd=4,xlim=c(-1.8,1.2),
  ylim=c(-1,1.2),mar=c(0.1,0.1,2.1,0.1))
mtext(paste("b) parallel=TRUE, log(L) =",
  sprintf("%.4f",round(logLik(ard_fit1),4))),
  line=-1,adj=0.2)
plot(ard_fit2,width=TRUE,text=FALSE,color=TRUE,
  show.zeros=FALSE,max.lwd=4,xlim=c(-1.8,1.2),
  ylim=c(-1,1.2),mar=c(0.1,0.1,2.1,0.1))
mtext(paste("c) opt.method=\"optimParallel\", log(L) =",
  sprintf("%.4f",round(logLik(ard_fit2),4))),
  line=-1,adj=0.3)

plot of chunk unnamed-chunk-1

That’s it!

No comments:

Post a Comment

Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.