I have created a graphing function:
plotfun = function(dat, pos, tetrad.name=NULL, snp.cols=c("blue", "red", "lightgray")){
plot(1,1, type="n", xlim=c(min(pos), max(pos)), ylim=c(0.75,4.25), yaxt="n", xaxt="n", main=paste("CCT6 -",tetrad.name), xlab="", ylab="", bty="n", cex=.75)
abline(h=1:4, lty="dotted")
tmpnull = sapply(1:4, function(n) points(pos, rep((4:1)[n],length(pos)), col=snp.cols[dat[n,]], pch=16))
mtext(c("a", "b", "c", "d"), side=2, line=0.5, at=4:1, las=1, cex=.5)
}
I am trying to use this graphing function to graph a subset of matrices that I have indexed from a larger list (x in this example). I am using sapply to graph all of the matrices individually:
sapply(1:69, function(n) plotfun(dat=matrix.transform(x[[n]]), pos=cct6.pos, tetrad.name= n ))
My problem is I can’t figure out how to have the plot title read as the list number attached to each matrix. Instead, it labels them 1:69, losing the information that from the indexed input. For example if the first input is cct6[[35]] I’d like the plot title to read "CCT6-35" not "CCT6-1"
Sorry if this is a basic question. I’m just stuck on this…
Change your
main= ...argument a line in the plot call within ‘plotfun’ with this snippet:When I tried this with a simple test case I found that the lazy evaluation aspect resulted in (not an error but a failure to properly label the plots. Adding a force() cal fixed that issue. Compare these two: