Skip to content
Prev 78379 / 398502 Next

grob questions

On 10/4/05, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
That certainly helps although some examples would be nice.

1. I understand that in the original example:

	grid.newpage()
	pushViewport(viewport(w = 0.5, h = 0.5))
	myplot <- gTree(name = "myplot",
	  children = gList(rectGrob(name = "box", gp = gpar(col = "grey")),
		  xaxisGrob(name = "xaxis")))
	grid.draw(myplot)
	grid.edit("myplot::xaxis", at = 1:10/11)
	grid.edit("myplot::xaxis::labels", label = round(1:10/11, 2))
	grid.edit("myplot::xaxis::labels", y = unit(-1, "lines"))

we can do this:

	grid.get("myplot::xaxis::labels")$label

and without specifying complete paths it can be done like this:

	get.grid("labels")$label

so I am ok on this one.


2.  But going back to:

 https://www.stat.math.ethz.ch/pipermail/r-help/2005-October/078653.html
 https://www.stat.math.ethz.ch/pipermail/r-help/2005-October/078656.html

I see you mention that vp= is always strict so is there a way to
do this somehow:

library(grid)
vp <- vpTree(
	viewport(layout=grid.layout(2,2), name="layout"),
	children=vpList(
		viewport(layout.pos.col = 1, layout.pos.row=1, name="tl"),
		viewport(layout.pos.col = 2, layout.pos.row=2, name="br")
	)
)

grobs <- gList(
	rectGrob(vp=vpPath("layout","tl")),
	textGrob("Top left", vp=vpPath("layout","tl")),
	textGrob("Bottom right", vp=vpPath("layout","br"))
)

grid.draw(gTree(childrenvp=vp, children = grobs))

without repeating "layout" three times in the definition of the
grobs object?