grid.newpage()
pushViewport(viewport(width=unit(.5, "npc"),
height=unit(.5, "npc")))
grid.rect()
w <- convertNative(unit(1, "inches"))
h <- convertNative(unit(1, "inches"), "y")
# This rectangle starts off life as 1in square, but if you
# resize the device it will no longer be 1in square
grid.rect(width=unit(w, "native"), height=unit(h, "native"),
gp=gpar(col="red"))
popViewport(1)
# How to use grid.convert(), etc instead
convertNative(unit(1, "inches")) ==
convertX(unit(1, "inches"), "native", valueOnly=TRUE)
convertNative(unit(1, "inches"), "y", "dimension") ==
convertHeight(unit(1, "inches"), "native", valueOnly=TRUE)
Run the code above in your browser using DataLab