Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to plot in a single plot different outputs of a function that internally uses par-mfrow?
    text
    copied!<p>I'm using a function that among several things plots the results in two panels using <code>par(mfrow = c(1, 2))</code>.</p> <p>I would like to run the function with three different datasets and plot the outputs together so that each one is in a row, as if I were using <code>par(mfrow = c(3, 2))</code>.</p> <p>If there a way of doing this without modifying the function itself?</p> <p>Probably basic issue, but help very much appreciated. </p> <p>The function is a little bit long, but the relevant part plots a PCoA:</p> <pre><code># perform classical multidimensional sclaing (PCoA) of the dist matrix acop &lt;- cmdscale(dat.d, k = nrow(as.matrix(dat.d)) - 1, eig = TRUE) # keep n-1 eigenvalues axes.tot &lt;- acop$eig # eig are the n eigenvalues computed by cmdscale. Axes are ranked by their eigenvalues, so the first axis has the highest eigenvalue, the second axis has the second highest eigenvalue, etc. inertia &lt;- sum(acop$eig[acop$eig &gt; 0]) percents &lt;- round(as.numeric(100 * axes.tot/inertia), digits = 0) # The eigenvalues represent the variance extracted by each axis, here they are expressed as a percentage of the sum of all eigenvalues (i.e. total variance). par() par(mfrow = c(1, 2), pty = "s") coord1 &lt;- acop$points[, c(1, 2)] # points is a matrix whose rows give the coordinates of the points chosen to represent the dissimilarities col.grps &lt;- data.frame(vect.grps, coord1) # plot so that the maximum variance is projected along the first axis, then on the second and so on plot(coord1, asp = 1, cex = 0.1, xlab = paste("Axis 1 ", "(", percents[1], " % variance explained)", sep = ""), ylab = paste("Axis 2 ", "(", percents[2], " % variance explained)", sep = ""), main = "", type = "n", bty = "n") abline(h = 0, lty = 2, col = "grey") abline(v = 0, lty = 2, col = "grey") if (length(vect.grps) == nrow(as.matrix(dat.d))) { for (g in 1:length(names.grps)) { text(x = coord1[col.grps[, 1] == names.grps[g], 1], y = coord1[col.grps[, 1] == names.grps[g], 2], labels = names.grps[g], col = topo.col[g], cex = 0.7) } } else { points(coord1, pch = 19, col = "blue", cex = 0.5) } coord1 &lt;- acop$points[, c(3, 4)] col.grps &lt;- data.frame(vect.grps, coord1) plot(coord1, asp = 1, cex = 0.1, xlab = paste("Axis 3 ", "(", percents[3], " % variance explained)", sep = ""), ylab = paste("Axis 4 ", "(", percents[4], " % variance explained)", sep = ""), main = "", type = "n", bty = "n") abline(h = 0, lty = 2, col = "grey") abline(v = 0, lty = 2, col = "grey") if (length(vect.grps) == nrow(as.matrix(dat.d))) { for (g in 1:length(names.grps)) { text(x = coord1[col.grps[, 1] == names.grps[g], 1], y = coord1[col.grps[, 1] == names.grps[g], 2], labels = names.grps[g], col = topo.col[g], cex = 0.7) } } else { points(coord1, pch = 19, col = "blue", cex = 0.5) </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