deviceLoc {grid} | R Documentation |
Convert Viewport Location to Device Location
Description
These functions take a pair of unit objects and convert them to a pair of device locations (or dimensions) in inches (or native device coordinates).
Usage
deviceLoc(x, y, valueOnly = FALSE, device = FALSE)
deviceDim(w, h, valueOnly = FALSE, device = FALSE)
Arguments
x , y , w , h |
A unit object. |
valueOnly |
A logical indicating. If |
device |
A logical indicating whether the returned values should be in inches or native device units. |
Details
These functions differ from the functions like convertX()
because they convert from the coordinate systems within a viewport
to inches on the device (i.e., from one viewport to another) and
because they only deal with pairs of values (locations or dimensions).
The functions like convertX()
convert between different units within
the same viewport and convert along a single dimension.
Value
A list with two components, both of which are unit object in inches
(unless valueOnly
is TRUE
in which case
both components are numeric).
Warning
The conversion is only valid for the current device size. If the device is resized then at least some conversions will become invalid.
Furthermore, the returned value only makes sense with respect to the entire device (i.e., within the context of the root viewport).
Author(s)
Paul Murrell
See Also
Examples
## A tautology
grid.newpage()
pushViewport(viewport())
deviceLoc(unit(1, "inches"), unit(1, "inches"))
## Something less obvious
grid.newpage()
pushViewport(viewport(width=.5, height=.5))
grid.rect()
x <- unit(1, "in")
y <- unit(1, "in")
grid.circle(x, y, r=unit(2, "mm"))
loc <- deviceLoc(x, y)
loc
upViewport()
grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))
## Something even less obvious
grid.newpage()
pushViewport(viewport(width=.5, height=.5, angle=30))
grid.rect()
x <- unit(.2, "npc")
y <- unit(2, "in")
grid.circle(x, y, r=unit(2, "mm"))
loc <- deviceLoc(x, y)
loc
upViewport()
grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))