Guohui Ding
2008-Feb-29 07:12 UTC
[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?
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]]
Prof Brian Ripley
2008-Feb-29 08:40 UTC
[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?
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
Greg Snow
2008-Feb-29 16:32 UTC
[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?
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. >