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

Greg Snow Greg.Snow at imail.org
Fri Feb 29 17:32:59 CET 2008


Look at the cnvrt.coords function in the TeachingDemos package.  

You should be able to use that function to transform from user
coordinates to device coordinates (where 0 is left/bottom and 1 is
right/top), then multiply the device coordinates by the resolution to
get the pixel numbers.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Guohui Ding
> Sent: Friday, February 29, 2008 12:12 AM
> To: R help (E-mail)
> Subject: [R] How to convert the "user coordinate system" in R 
> graph to"normal coordinate system" whose origin is the 
> upper-leftcornner of the drawing area?
> 
> 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?
> 
>      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.
> 



More information about the R-help mailing list