Hi,
I can think of two situations but it's hard to tell without reproducible code,
1) the page layout is a result of facetting (possibly with a dummy
factor) or wrapping, in which case there should be one common legend
and its default position should be nicely aligned in the page
2) you don't want to use the first option, so you've placed two
unrelated ggplots on a page using grid.layout or other viewport
functions. Perhaps you can do something like this,
- create your two plots p1 and p2
- save the legend of p1 as a grob,
p3 <- p1 + opts(keep= "legend_box")
- strip the legend of p1 and p2,
p1 <- p1 + opts(legend.position = "none")
p2 <- p2 + opts(legend.position = "none")
- create three viewports on the page and print p1, p2, p3.
Example:
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
d <- qplot(carat, price, data=dsamp, colour=clarity)
p3 <- d + opts(keep= "legend_box")
p1 <- d + opts(legend.position = "none")
p2 <- d + opts(legend.position = "none")
p3
pushViewport(viewport(x=0.4,y=0.75, width = 0.8, height = 0.5, angle = 0,
name = "topleftvp"))
grid.rect()
print(p1, vp="topleftvp")
upViewport()
pushViewport(viewport(x=0.4,y=0.25, width = 0.8, height = 0.5, angle = 0,
name = "botleftvp"))
grid.rect()
print(p2, vp="botleftvp")
upViewport()
HTH,
baptiste
--
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone:
+44 1392 264187
http://newton.ex.ac.uk/research/emag
______________________________