开发者

pushViewport -> layout.pos.col possible with doubles?

I am wondering if it is possible to specify grid viewports with double like this:

pushViewport(viewport(layout.pos.row=1, layout.pos.col=1.5))
popViewport() 

When I'm trying this I get row 1 and col 1.

But I want to have half of col 1 and half of col 2.

Has开发者_如何学Python anyone a hint for me?


PROBABLY you cannot do it by layout.pos.row and layout.pos.col. Simple workaround is to specify position and size:

grid.newpage()
pushViewport(viewport(layout=grid.layout(2, 2)))
grid.rect(gp=gpar(fill=1),vp=viewport(layout.pos.col=1,layout.pos.row=1))
grid.rect(gp=gpar(fill=2),vp=viewport(layout.pos.col=1,layout.pos.row=2))
grid.rect(gp=gpar(fill=3),vp=viewport(layout.pos.col=2,layout.pos.row=1))
grid.rect(gp=gpar(fill=4),vp=viewport(layout.pos.col=2,layout.pos.row=2))

pushViewport(viewport(x=unit(0.5, "npc"), width=unit(0.5, "npc"), 
  y=unit(0.75, "npc"), height=unit(0.5, "npc")))
grid.rect(gp=gpar(fill="white"))

also, I think you can write a wrapper function to do this by specifying pos.col and pos.row in double, like this:

vpvp <- function(pos.col, pos.row){
  cvp <- current.viewport()
  nrow <- cvp$layout$nrow
  ncol <- cvp$layout$ncol
  w <- unit(1/ncol, "npc")
  h <- unit(1/nrow, "npc")
  x <- unit((pos.col-0.5)/ncol, "npc")
  y <- unit(1-(pos.row-0.5)/nrow, "npc")
  viewport(x=x, y=y, width=w, height=h)
}

grid.newpage()
pushViewport(viewport(layout=grid.layout(2, 3)))
grid.rect(gp=gpar(fill=1),vp=viewport(layout.pos.col=1,layout.pos.row=1))
grid.rect(gp=gpar(fill=2),vp=viewport(layout.pos.col=1,layout.pos.row=2))
grid.rect(gp=gpar(fill=3),vp=viewport(layout.pos.col=2,layout.pos.row=1))
grid.rect(gp=gpar(fill=4),vp=viewport(layout.pos.col=2,layout.pos.row=2))
grid.rect(gp=gpar(fill=5),vp=viewport(layout.pos.col=3,layout.pos.row=1))
grid.rect(gp=gpar(fill=6),vp=viewport(layout.pos.col=3,layout.pos.row=2))

pushViewport(vpvp(pos.col=2.5, pos.row=1.5))
grid.rect(gp=gpar(fill="white"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜