[R] Using subplot (from Hmisc) along with par(mfrow)

David Winsemius dwinsemius at comcast.net
Fri Jul 4 03:51:26 CEST 2014


On Jul 3, 2014, at 12:45 PM, Cory Champagne wrote:

> 
>   Hello all,
>   I think this should be a relatively easy solution involving par but I can't
>   figure it out, involving subplot:
>   I'm  making  a  three-figure plot, each with a subplot.  Here's simple
>   reproducible code below.  But each plot seems to call the original par
>   setting and redraws the new plot in the first position, rather than adding
>   subsequent plots in a single plot window.
>   Can someone tell me how to fix this so the result is three figures, each
>   containing a subplot, all within a single plot window?
>   Thanks,
>   -Cory
>   library(Hmisc)    # subplot from the Hmisc package
>   par(mfrow=c(3,1) )    # set mfrow for 3 rows and 1 column.
>   plot(1:10, 1:10, main = "Plot 1")
>       subplot(plot(10,10, xlab="", ylab=""), x=2, y=8, size = c(0.5, 0.5) )
>   plot(11:20, 11:20, main = "Plot 2")
>       subplot(plot(10,10, xlab="", ylab=""), x=12, y=18, size = c(0.5, 0.5)
>   )
>   plot(21:30, 21:30, main = "Plot 3")
>       subplot(plot(10,10, xlab="", ylab=""), x=22, y=28, size = c(0.5, 0.5)
>   )

Need to read a bit further down below the 'mfrow' and 'mfcol' arguments in par, specifically until you get to 'mfg':

library(Hmisc)    
  par(mfrow=c(3,1) )    
  plot(1:10, 1:10, main = "Plot 1")
      subplot(plot(10,10, xlab="", ylab=""), x=2, y=8, size = c(0.5, 0.5) )
  par(mfg=c(2,1) ); plot(11:20, 11:20, main = "Plot 2")
      subplot(plot(10,10, xlab="", ylab=""), x=12, y=18, size = c(0.5, 0.5)
  )
  par(mfg=c(3,1)); plot(21:30, 21:30, main = "Plot 3")
      subplot(plot(10,10, xlab="", ylab=""), x=22, y=28, size = c(0.5, 0.5)
  )

I suspect that the subplot manipulations of par settings are the cause of the problem. It is restoring the mfg pointer.

-- 
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list