Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I store a list of ggplots to use in multiplot without overwriting previous plots?
    text
    copied!<p>I want to plot some heatmaps of covariance/correlation matrices in a multiplot using an object created from another function (the <code>cd</code> parameter below). The covariance matrices are stored in an array of 3 dimensions, so that <code>cd$covmat[,,i]</code> calls the ith covariance matrix.</p> <p>Originally I had some issues with this with having the same plot replicated. However, I discovered I had an environment issue. I've tried resolving this several ways, with the code below being the most recent, but I can't figure out why it's not reading it properly.</p> <p>Is there a particular reason for this? I've tried including and excluding the environment parameter (which I hopefully shouldn't need) and I've tried directly using the <code>cd$covmat[,,i]</code> in the <code>aes()</code> parameter.</p> <pre><code>drawCovs&lt;-function(cd,ncols){ require(ggplot2) coords=expand.grid(x=1:cd$q,y=1:cd$q) climits = c(-1,1)*max(cd$covmat) cd$levels=c(cd$levels,"Total") covtext=ifelse(!(cd$use.cor),'Covariance','Correlation') plots=list() cmat=list() for (i in 1:(nlevels+1)){ cmat[[i]]&lt;-cd$covmat[,,i] .e&lt;-environment plots[[i]]&lt;-ggplot(environment=.e)+geom_tile(aes(x=coords$x,y=coords$y, fill=as.numeric(cmat[[i]]),color='white'))+ scale_fill_gradient(covtext,low='darkblue',high='red',limits=climits)+ylab('') +xlab('')+guides(color='none')+scale_x_discrete(labels=cd$varnames, limits=1:cd$q, expand=c(0,0))+scale_y_discrete(labels=cd$varnames, limits=1:cd$q, expand=c(0,0))+theme(axis.text.x = element_text(angle = 90, hjust = 1))+labs(title=paste0(covtext,"s of data, ",cd$levels[i])) } multiplot(plotlist=plots,cols=ncols) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload