Skip to content
Prev 152418 / 398500 Next

grid layout scaling viewport width based solely on height

Hi
Peter Cowan wrote:
Sorry, I'm not completely sure what you want to end up with, but do
either of the following come close ?

# Side plots square and attached to each other
# With "tall" plot, get gaps top and bottom
# With "wide" plot, get gap on the right
lay1 <- grid.layout(1, 2, widths=c(10, 1))
lay2 <- grid.layout(10, 1, respect=TRUE, just="left")

# grid.newpage()
pushViewport(viewport(width=.8, height=.8, layout=lay1))
grid.rect(gp=gpar(col="grey"))

pushViewport(viewport(layout.pos.col=1))
grid.rect(gp=gpar(fill="grey"))
popViewport()

pushViewport(viewport(layout.pos.col=2,
                      layout=lay2))
for (i in 1:10) {
    pushViewport(viewport(layout.pos.row=i))
    grid.rect(gp=gpar(fill="light grey"))
    popViewport()
}
popViewport()


# Side plots square and separate from each other
# With "tall" plot, get gaps between vertically
# With "wide" plot, get gap on the right
lay1 <- grid.layout(10, 2, widths=c(10, 1))

# grid.newpage()
pushViewport(viewport(width=.8, height=.8, layout=lay1))
grid.rect(gp=gpar(col="grey"))

pushViewport(viewport(layout.pos.col=1))
grid.rect(gp=gpar(fill="grey"))
popViewport()

for (i in 1:10) {
    pushViewport(viewport(layout.pos.col=2,
                          layout.pos.row=i))
    pushViewport(viewport(x=0, width=unit(1, "snpc"),
                          height=unit(1, "snpc"), just="left"))
    grid.rect(gp=gpar(fill="light grey"))
    popViewport(2)
}

Paul