[R] Going "backwards" through plot panels

Henrik Bengtsson hb at biostat.ucsf.edu
Thu Jun 21 00:53:04 CEST 2012


FYI, from help("layout", package="graphics"):

"[...]
Warnings
These functions are totally incompatible with the other mechanisms for
arranging plots on a device: par(mfrow), par(mfcol) and split.screen."

/Henrik


On Wed, Jun 20, 2012 at 3:17 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> That's fantastic Richard and much appreciated. It doesn't seem to play
> intuitively with layout() [and isn't documented to do so] but do you
> happen to know an alternative that works nicely with layout()?
>
> I'm trying to wrap my head around something like this:
>
> layout(matrix(c(1,1,2,3), byrow = TRUE, ncol = 2))
> plot(1:5)
> par("mfg") # So the big panel seems to be c(1,1,2,2)
>
> plot(1:5)
> plot(1:5)
>
> # i and j seem not to make too much sense?
> par("mfg" = c(2,1,2,2))
> points(5:1, type = "l", col = 2) # Why does this go back to bottom right?
>
> par("mfg" = c(1,2,2,2))
> points(5:1, type = "l", col = 3) # Bottom left apparently?
>
> par("mfg" = c(1,1))
> points(5:1, type = "l", col = 4) # Aspect ratio is funny or maybe its
> the margins?
>
> That last one is particularly strange to me. Anyways, it's much
> appreciated and I think it's worth giving up the variable sizing
> layout() affords to use this - thanks again,
>
> Michael
>
> On Wed, Jun 20, 2012 at 4:46 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
>> ?par
>> read about mfg
>> which allows you to index into the arrangement set by mfrow and mfcol
>>
>> Rich
>>
>> On Wed, Jun 20, 2012 at 5:27 PM, R. Michael Weylandt
>> <michael.weylandt at gmail.com> wrote:
>>>
>>> R-helpers,
>>>
>>> I'm looking to set up multi-screen plots with layout() or
>>> par(mfrow/mfcol = ) but I'm not sure if there's an easy way to go
>>> "backwards" among the panels. E.g.
>>>
>>> layout(1:2)
>>> plot(1:4)
>>> plot(1:8)
>>>
>>> Here I'd like to put some more on the 1:4 plot (e.g., some points or a
>>> line or a legend) but everything goes onto the now active panel. I'm
>>> really looking for something like dev.set() but for the panels on a
>>> single device.
>>>
>>> I know the immediate work around is simply to do all that's necessary
>>> for each panel in the right order, but I'm setting up some
>>> end-user-facing plot functions and that might not be the easiest to
>>> ask of them. For speed / style / consistency, I'd really like to stay
>>> with base graphics, so a grid solution unfortunately isn't quite what
>>> I need.
>>>
>>> Happy to be told to RTFM if someone has a pointer to the right one,
>>>
>>> Michael
>>>
>>> ______________________________________________
>>> R-help at r-project.org 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.
>>
>>
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list