Hi,
I have been trying many of the suggested options
to place a legend outside plotting area, including
something like this:
par(xpd=T,
oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
But the aspect of the four plots gets compromised
when I change the margin settings. I cannot use mtext
because I need to use colors for the text. I tried
layout, but wouldn't let me include the legend, only
plots.
I would appreciate very much some more help.
Regards,
J
____________________________________________________________________________________Pinpoint
customers who are looking for what you sell.
RSiteSearch("legend outside plot")
will bring you many links to the discussions of this question.
layout perfectly allows everything.
typical sequence looks like this
This divides the device region by two parts one below another:
layout(matrix(c(1,2),byrow=TRUE), heights=[blah-blah-blah], [some other
arguments])
Then we plot on the first part:
plot( ... )
lines ( ... )
points ( ... )
grid( ... )
[ whatever you want on the plotting area]
Then we finish plotting on the first part of the layout matrix and come to
the next, legend part.
The only thing to do is placing the legend in the top left corner.
plot.new();
plot.window(c(0,1), c(0,1));
legend(0,1, [ legend text ] )
Judith Flores wrote:>
> Hi,
>
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
>
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
>
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
>
> I would appreciate very much some more help.
>
> Regards,
>
> J
>
--
View this message in context:
http://www.nabble.com/Legend-outside-plotting-area-tf3794564.html#a10735956
Sent from the R help mailing list archive at Nabble.com.
Judith,
you might try split.screen() and related functions, see ?screen.
Example:
split.screen(c(1,2)) # 1 row, 2 columns
split.screen(c(2,2), screen = 1) # split left column into 2x2
for(i in 3:6) { screen(i); plot(1:10) }
screen(2)
plot(1, type="n", axes=F, ann=F) # empty plot
legend("center", pch=1, legend="Data")
Regards,
Carsten
> Hi,
>
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
>
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
>
>
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
>
> I would appreciate very much some more help.
>
> Regards,
>
> J
Quoting Judith Flores <juryef at yahoo.com>:> Hi, > > I have been trying many of the suggested options > to place a legend outside plotting area, including > something like this: > > par(xpd=T, > oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0) > > > But the aspect of the four plots gets compromised > when I change the margin settings. I cannot use mtext > because I need to use colors for the text. I tried > layout, but wouldn't let me include the legend, only > plots. > > I would appreciate very much some more help. > > Regards, > > Jyou can use 'mtext' with colors... mtext("whatever", col="blue"...) -- Dr. Jose I. de las Heras Email: J.delasHeras at ed.ac.uk The Wellcome Trust Centre for Cell Biology Phone: +44 (0)131 6513374 Institute for Cell & Molecular Biology Fax: +44 (0)131 6507360 Swann Building, Mayfield Road University of Edinburgh Edinburgh EH9 3JR UK
Judith,
Haven't tried it in anger myself, but two things suggest themselves. The
first is to use the lattice package, which seems to draw keys (autokey option)
outside the plot region by default. Look at the last couple of examples in
?xyplot. May save a lot of hassle...
In classical R graphics, have you tried plotting everything explicitly inside a
plot region with margins at zero?
For example:
plot.new()
par(mar=c(0,0,0,0))
plot.window(xlim=c(-2,11), ylim=c(-3,13))
points(1:10,1:10, pch=1)
points(1:10,10:1, pch=19)
par(srt=90)
text(x=-2, y=5, "y-axis", pos=1, offset=0.5)
par(srt=0)
text(c(5,5), c(13,-1), labels=c("Title","x-axis"), pos=1,
offset=0.7, cex=c(1.5,1))
rect(-0.2,-0.2, 11.2,11.2)
axis(side=1, at=0:10, pos=-0.2)
axis(side=2, at=0:10, pos=-0.2)
legend(x=5, y=-2, xjust=0.5, pch=c(1,19), legend=c("Type 1",
"Type 19"), ncol=2)
All very tedious, but it works. Also, fiddling around with things like pretty()
on the data can automate most of the above positional choices if you're so
inclined. And legend(..., plot=F) returns the legend size and coordinates if you
want to fine-tune the location.
Steve E
>>> <J.delasHeras at ed.ac.uk> 23/05/2007 13:14:54 >>>
Quoting Judith Flores <juryef at yahoo.com>:
> Hi,
>
> I have been trying many of the suggested options
> to place a legend outside plotting area, including
> something like this:
>
> par(xpd=T,
> oma=par()$oma+c(4.5,0,1.5,0),mar=par()$mar+c(1,0,1,0)
>
>
> But the aspect of the four plots gets compromised
> when I change the margin settings. I cannot use mtext
> because I need to use colors for the text. I tried
> layout, but wouldn't let me include the legend, only
> plots.
>
> I would appreciate very much some more help.
>
> Regards,
>
> J
*******************************************************************
This email and any attachments are confidential. Any use, co...{{dropped}}