[R] Returning to normal after call to layout()

Jean Eid jeaneid at chass.utoronto.ca
Fri Dec 10 15:19:31 CET 2004


Here's tow examples that do what you want (the way I understand them).


layout(matrix(c(1,0,1,0), byrow = TRUE))
plot(10:100)
par(xpd=NA)
co <- par("usr")
legend(co[1], -10, legend=c("Hello long time no see","\n" , "and My day
was great","\n",  "How was yours"), text.width=95, col="red",,
text.col=c("red","blue", "green"),pch=c(1,NA,2,NA,3), cex=1 )

plot.new()
plot(1:10, bty="n", type="n", xlab="", ylab="", axes=F)
co1 <- par("usr")
legend(co1[1], co1[2], legend=c("Hello long time no see","\n\n\n\n\n\n" ,
"and My day was great","\n\n\n\n\n\n",  "How was yours",
"\n\n\n\n\n\n\n"), text.width=9.5, col="red",, text.col=c("red","blue",
"green"),pch=c(1,NA,2,NA,3,NA), cex=1 )



Unfortunately, to my knowledge there are no ways to set the height on
legend so I do that by including "\n" in the legend wich is the end of
line character....

Hope this help. Note if you are giving a seminar or lecture I do not think
it is appropriate to do it the second way i.e. plot on one window legend
on the other....


Hope this helps,


Jean,


On Fri, 10 Dec 2004, Petr Pikal wrote:

>
>
> On 10 Dec 2004 at 12:20, michael watson (IAH-C) wrote:
>
> > Hi Petr
> >
> > Yes thanks I did get your response and it was helpful.  However, I
> > have now resorted to using barplot() to draw a legend (as all I wanted
> > was colored boxes and text) and it works very well for my needs.
> >
> > Basically, with layout() I'm not getting what I would expect, which
> > may be a problem with my expectation rather than anything else.  Like
> > I say, I have a function which draws a plot, using layout to divide
> > the plotting region into top and bottom.  Fine.  If the user calls my
> > function, and then another plotting function, I would expect the new
> > plotting function to overwrite the whole of the old plot - but it
> > doesn't, it draws the new plot in the top half of the old plot, and
> > clears the bottom plot.  So what I want is something which says, after
> > calling layout(), "OK, I'm done plotting in two different regions, I
> > want you to treat the current device as a single region again".
> >
> > In a previous package I wrote, when using split.screen() to divide up
> > the plotting region, dev.off() could be used for this purpose.  But
> > dev.off() closes the window/plot that I created using layout().
>
> Hi
>
> from the layout help page example (shortened)
>
> > def.par <- par(no.readonly = TRUE)
> > layout(matrix(c(1,2), 2, 1))
> > plot(1,3)
> > plot(1,2)
> > par(def.par)
> > plot(1,1)
> >
> suppose to be exactly what you want
>
> Cheers
> Petr
>
>
> >
> > Mick
> >
> > -----Original Message-----
> > From: Petr Pikal [mailto:petr.pikal at precheza.cz]
> > Sent: 10 December 2004 12:12
> > To: michael watson (IAH-C)
> > Cc: r-help at stat.math.ethz.ch
> > Subject: Re: [R] Returning to normal after call to layout()
> >
> >
> >
> >
> > On 10 Dec 2004 at 11:47, michael watson (IAH-C) wrote:
> >
> > > Hi
> > >
> > > I have a function which draws a plot, using the layout() function to
> > > divide the screen into two parts.  The function works fine, but then
> > > my next call to plot() draws the plot in the first section of the
> > > plot
> >
> > > I've just drawn using layout() - whereas what I want it to do is
> > > create a new plot.
> > >
> > > I tried using dev.off() but that just closes the layout plot window,
> > > which is not what I want.  So my question is - after using the
> > > layout() function, "layout(matrix(c(1,2), 2, 1))", how do I tell R
> >
> > Hi
> >
> > what is wrong on this:
> >
> > layout(matrix(c(1,2), 2, 1))
> > plot(1,1)
> > plot(1,2)
> > windows() #opens the new graphic device see ?device, ?windows
> > plot(1,3)
> >
> > BTW did you read my previous post to your question about legend
> > on a new window?
> >
> > Cheers
> > Petr
> >
> >
> > > that the next call to a plotting function should use a new window,
> > > and
> >
> > > not the layout window?  I've looked in ?layout but there doesn't
> > > seem to be anything in there.
> > >
> > > Thanks
> > > Mick
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide!
> > > http://www.R-project.org/posting-guide.html
> >
> > Petr Pikal
> > petr.pikal at precheza.cz
> >
> >
>
> Petr Pikal
> petr.pikal at precheza.cz
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list