Rev 78759 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/grid/man/deviceLoc.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2013 R Core Team% Distributed under GPL 2 or later\name{deviceLoc}\alias{deviceLoc}\alias{deviceDim}\title{ Convert Viewport Location to Device Location }\description{These functions take a pair of unit objects and convertthem 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{\item{x, y, w, h}{ A unit object. }\item{valueOnly}{ A logical indicating. If \code{TRUE} thenthe function does not return a unit object, but rather only theconverted numeric values. }\item{device}{ A logical indicating whether the returned values shouldbe in inches or native device units. }}\details{These functions differ from the functions like \code{convertX()}because they convert from the coordinate systems within a viewportto inches on the device (i.e., from one viewport to another) andbecause they only deal with pairs of values (locations or dimensions).The functions like \code{convertX()} convert between different units withinthe same viewport and convert along a single dimension.}\value{A list with two components, both of which are unit object in inches(unless \code{valueOnly} is \code{TRUE} in which caseboth components are numeric).}\author{ Paul Murrell }\section{Warning}{The conversion is only valid for the current device size.If the device is resized then at least some conversions willbecome invalid.Furthermore, the returned value only makes sense with respect tothe entire device (i.e., within the context of the root viewport).}\seealso{ \code{\link{unit}} }\examples{## A tautologygrid.newpage()pushViewport(viewport())deviceLoc(unit(1, "inches"), unit(1, "inches"))## Something less obviousgrid.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)locupViewport()grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))## Something even less obviousgrid.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)locupViewport()grid.circle(loc$x, loc$y, r=unit(1, "mm"), gp=gpar(fill="black"))}\keyword{dplot}