Using subplot (from Hmisc) along with par(mfrow)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using subplot (from Hmisc) along with par(mfrow)

Cory Champagne

   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)
   )
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Using subplot (from Hmisc) along with par(mfrow)

David Winsemius

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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Using subplot (from Hmisc) along with par(mfrow)

glsnow
In reply to this post by Cory Champagne
The subplot function in the TeachingDemos package is more up to date
than the version in Hmisc (the Hmisc version is a copy of an earlier
version of the one in TeachingDemos).  If you replace library(Hmisc)
with library(TeachingDemos) (with a recent version of TeachingDemos
installed) then the code works as you expect.

On Thu, Jul 3, 2014 at 1:45 PM, Cory Champagne <[hidden email]> 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)
>    )
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Using subplot (from Hmisc) along with par(mfrow)

Frank Harrell
In reply to this post by Cory Champagne
Greg I just re-copied the latest subplot and its help file from  
TeachingDemos to Hmisc for the next release.  Thanks for pointing this out.
Frank

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Frank Harrell
Department of Biostatistics, Vanderbilt University