screen2data.Rd
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).
x coordinates of locations to convert or a two-column matrix
(if y
is missing)
y coordinates of locations to convert (if missing x
must be a matrix and the second column of x
is interpreted as
y
)
width of the figure region (usually the size of the resulting file in pixels)
height of the figure region (usually the size of the resulting file in pixels)
resolution (only used to compute the width and height from figure size if they are not specified
the `plt' parameter
the `usr' parameter
if set to TRUE
then y
axis in pixels is
assumed to be flipped (0 on top)
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)
#> Warning: calling par(new=TRUE) with no plot
#> Warning: calling par(new=TRUE) with no plot
#> Error in plot.new(): figure margins too large
## where on the bitmap is the data point 0,0 ?
data2screen(0, 0)
#> x y
#> 59.04 73.44
## if I click on 200, 100 with flipped coordinates, what coordinates do
## I hit?
screen2data(200, 100, flip=TRUE)
#> x y
#> 3.838780 1.499025
## go there and back
screen2data(data2screen(c(0, 0.5), c(1, 0.5)))
#> x y
#> [1,] 0.0 1.0
#> [2,] 0.5 0.5