screen2data | R Documentation |
screen2data
converts between screen (pixel) coordinates of device
output and the data coordinates.
data2screen
performs the inverse conversion.
Both functions can be parametrized manually but default to obtaining all
necessary parameters from the active graphics device. It is most useful
when used with bitmap dvices such as the Cairo device (see Cairo
package) for the purpose of adding interactivity (e.g., via JavaScript).
screen2data(x, y, width = par("fin")[1] * dpi, height = par("fin")[2] * dpi, dpi = 72, plt = par("plt"), usr = par("usr"), flip = FALSE) data2screen(x, y, width = par("fin")[1] * dpi, height = par("fin")[2] * dpi, dpi = 72, plt = par("plt"), usr = par("usr"), flip = FALSE)
x |
x coordinates of locations to convert or a two-column matrix
(if |
y |
y coordinates of locations to convert (if missing |
width |
width of the figure region (usually the size of the resulting file in pixels) |
height |
height of the figure region (usually the size of the resulting file in pixels) |
dpi |
resolution (only used to compute the width and height from figure size if they are not specified |
plt |
the ‘plt’ parameter |
usr |
the ‘usr’ parameter |
flip |
if set to |
The result is a two-column matrix with the columns x
and
y
. The special case of one row input is returned as a named
vector of length two.
If x
and y
are vectors they are recycled to match.
plot(0:1,0:1) ## where on the bitmap is the data point 0,0 ? data2screen(0, 0) ## if I click on 200, 100 with flipped coordinates, what coordinates do ## I hit? screen2data(200, 100, flip=TRUE) ## go there and back screen2data(data2screen(c(0, 0.5), c(1, 0.5)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.