[R] window (x,y) co-ordinates of datapoints

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 9 13:34:35 CEST 2007


On Tue, 9 Oct 2007, Samuel Kemp wrote:

> Hi,
>
> In the getGraphicsEvent function the (x,y) co-ordinates returned from the
> mouse move are in relation to where the mouse is located within the device
> window  (i.e. the lower left corner of the window is '(0,0)',  the upper
> right is '(1,1)').

You do realise that is specific to the windows() device?  The 
getGraphicsEvent() help does not say what happens on the windows() device 
if 'rescale != "R"', when the 'window' is not simply related to the device 
surface -- so I'll ignore that.

> Is there a way of returning the (x,y) co-ordinates of
> data points plotted where instead of x and y being the actual data points
> they are the coordinates of the device window.
>
> e.g. below is a simple plot of x,y data
>
> x <- 1:10
> y <- x*20
> plot(x,y)
>
>> x[4]
> 4
>
>> y[4]
> 80
>
> what I actually want to know is where (x[4],y[4]) is within the device
> window.
>
> Does any-one have any ideas?

Read ?par and the descriptiuon in 'An Introduction to R'.  "din", "fin", 
"mai", "omi", "pin" and "usr" are relevant.

You have only one figure, no outer margins and linear scales.  For your 
example on Linux (after resizing) I got

> par("din")
[1] 9.162549 6.407743
> par("mai")
[1] 1.0407480 0.8366798 0.8366798 0.4285433
> par("pin")
[1] 7.897326 4.530315

which tells me the plot region has corners (0.8366798, 1.0407480) and 
(9.162549-0.8366798, 6.407743-0.4285433)

and

> par("usr")
[1]   0.64  10.36  12.80 207.20

tells me the user coordinates of those corners.  That suffices to do the 
mapping.

>
> Thanks in advance,
>
> Sam
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list