require(grid)
grid.newpage()
# Pushing a new VP to draw a rect within
pushViewport(viewport(x = unit(0.3, "npc"), y = unit(0.2, "npc"),
width = unit(0.1, "npc"), height = unit(0.3, "npc"),
xscale = c(0, 20), yscale = c(0, 10),
name = "testVP"))
grid.rect()
grid.export("create-test.svg", exportCoords = "file")
# Importing coordinate information
gridSVGCoords(readCoordsJS("create-test.svg.coords.js"))
# This should appear to be the same rect
grid.newpage()
pushViewport(viewportCreate("testVP.1"))
grid.rect()
# Let's see if the scales are accurate, should be:
# xscale: [0, 20]
# yscale: [0, 10]
current.viewport()$xscale
current.viewport()$yscaleRun the code above in your browser using DataLab