[R] How to convert the "user coordinate system" in R graph to "normal coordinate system" whose origin is the upper-left cornner of the drawing area?

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Feb 29 09:40:57 CET 2008


On Fri, 29 Feb 2008, Guohui Ding wrote:

> Dear friends,
>
>      The user coordiante system in the R graphics is easy to understand as
> it simply corresponds to the range of values on the axes of the plot.
> However, sometimes, we want to kown the coordinates of a region in other
> system, e.g., the normal coordinate system whose origin is the the
> upper-left cornner of the drawing area which is used to set the hot regions
> in the HTML image maps. Is there any suggestion?

See ?par and the explanation in 'An Introduction to R'.  In particular, 
'din', 'pin, 'mar'' and 'usr' contain most of the information you need, 
and will enable you to convert (0,0) to a position in inches on the 
device.  In R < 2.7.0 you'll have to do the conversion to pixels manually
(in 2.7.0 you can use dev.size()).

>
>     For example, I execute the code,
>
>> png("x.png",  width = 480, height = 480,
> +     pointsize = 12, bg = "white", res = 100);
>> plot(0, xlim=c(0, 100), ylim = c(0,100), type="n")
>> rect(0, 0, 100, 100)
>> points(0, 0, col = 'red')
>> dev.off()
>
> I will get a figure named "x.png". The resolution of this figure is 100 dpi
> and the width and height are 480 pixels when I opened it with Photoshop.
> When I move the cursor to the point drawed by points(0, 0, col = 'red'), I
> can find the position of this point is about (87, 376) [(x, y)]. I want to
> know how to convert the (0, 0) in the user coordinate system to this value?
>
> I look forward to hearing from you.
>
> --
> ADDRESS: Bioinformatics Center, Shanghai Institutes for Biological Sciences,
> Chinese Academy of Sciences
> 320 Yueyang Road, Shanghai 200031, P.R.China
> TELEPHONE: 86-21-54920086
>
> 	[[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