[R] grid.layout?
Patrick Connolly
p_connolly at slingshot.co.nz
Tue Mar 4 20:26:57 CET 2008
platform x86_64-unknown-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 2
minor 6.2
year 2008
month 02
day 08
svn rev 44383
language R
version.string R version 2.6.2 (2008-02-08)
The following code does almost everything I want except the red
rectangle should be aligned flush with square. There's something I
haven't understood about the grid.layout function. The second time I
use it, it does what I expect, but there's something wrong with the
first one.
require(grid)
N <- 5
variates <- LETTERS[1:N]
grid.newpage()
plot.square <- 2 * length(variates)# cm
text.wid <- 3 # cm
vp <- grid.layout(nrow = 1, ncol = 2,
widths = c(text.wid, plot.square),
heights = plot.square, default.units = "cm")
pushViewport(viewport(layout = vp, layout.pos.row = 1,
layout.pos.col = 2))
##
vpp <- grid.layout(nrow = length(variates),
ncol = length(variates),
widths = 2, heights = 2,
default.units = "cm")
pushViewport(viewport(layout = vpp))
for(i in seq(variates)){
for(j in seq(variates)){
pushViewport(viewport(layout = vpp, layout.pos.col = j,
layout.pos.row = i))
grid.rect(gp=gpar(lty='dashed'))
popViewport(1)
}
}
popViewport(1)
pushViewport(viewport(layout = vp, layout.pos.col = 1,
layout.pos.row = 1))
grid.rect(gp=gpar(col = "red", width = 3))
ylab.pos <- seq(variates)/length(variates)
ylab.pos <- ylab.pos - ylab.pos[1]/2
for(i in seq(variates)){
grid.text(rev(variates)[i], x = 0.9, gp=gpar(cex = .8),
y = ylab.pos[i], default.units = "npc",
just="right")
}
Suggestions about the more intelligent use of pushViewport and
popViewport would also be appreciated.
Thank you.
--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
___ Patrick Connolly
{~._.~} Great minds discuss ideas
_( Y )_ Middle minds discuss events
(:_~*~_:) Small minds discuss people
(_)-(_) ..... Anon
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
More information about the R-help
mailing list