Re: [R] Specifying relative position of text in a plot
On Thu, 13 Mar 2008, Tom La Bone wrote: Thanks for all of the suggestions. The key key here seems to be using the par function to change the coordinate system like so plot(rnorm(100), rnorm(100)) op - par(usr) par(usr = c(0, 1, 0, 1)) text(0.5,0.5,TEST) par(usr = op) Prof Ripley commented that this approach will also work on log plots, but I don't think I completely understand what is going on because this does not work for me plot(rlnorm(100), rlnorm(100),log=xy) op - par(usr) par(usr = c(0, 1, 0, 1)) text(0.5,0.5,TEST) par(usr = op) Any hints on what I am doing wrong with the log plots? Thanks again for the help. You need par(usr = c(0, 1, 0, 1), xlog=FALSE, ylog=FALSE) to set up a non-log coordinate system. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Specifying relative position of text in a plot
Thanks for all of the suggestions. The key key here seems to be using the par function to change the coordinate system like so plot(rnorm(100), rnorm(100)) op - par(usr) par(usr = c(0, 1, 0, 1)) text(0.5,0.5,TEST) par(usr = op) Prof Ripley commented that this approach will also work on log plots, but I don't think I completely understand what is going on because this does not work for me plot(rlnorm(100), rlnorm(100),log=xy) op - par(usr) par(usr = c(0, 1, 0, 1)) text(0.5,0.5,TEST) par(usr = op) Any hints on what I am doing wrong with the log plots? Thanks again for the help. Tom -- View this message in context: http://www.nabble.com/Specifying-relative-position-of-text-in-a-plot-tp16002549p16024549.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] Specifying relative position of text in a plot
What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. Tom -- View this message in context: http://www.nabble.com/Specifying-relative-position-of-text-in-a-plot-tp16002549p16002549.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Specifying relative position of text in a plot
Try this: plot(rnorm(100)) text(diff(par(usr)[1:2])/10, sum(par(usr)[3:4])/2, labels=Test) On 12/03/2008, Tom La Bone [EMAIL PROTECTED] wrote: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. Tom -- View this message in context: http://www.nabble.com/Specifying-relative-position-of-text-in-a-plot-tp16002549p16002549.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@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.
Re: [R] Specifying relative position of text in a plot
See ?par, entry usr. Either set a new coordinate system and use it, or convert 1/10 to user coordinates. In R-devel (2.7.0 to be) this is easier: text(grconvertX(0.1,npc), grconvertY(0.5, npc), some text) cnvrt.coords() in package TeachingDemos does something similar (although it doesn't use the standard R names for coordinate systems, and there are more than 5). On Wed, 12 Mar 2008, Tom La Bone wrote: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. Tom -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Specifying relative position of text in a plot
Tom La Bone asked: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. See the help of par: ?par Namely: plot(rnorm(100), rnorm(100)) pu - par()$usr x - pu[1] * 0.5 + pu[2] * 0.5 y - pu[3] * 0.1 + pu[4] * 0.9 text(x, y, the quick brown fox jumps over a lazy dog) Alberto Monteiro __ R-help@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.
Re: [R] Specifying relative position of text in a plot
I tested the main set of examples from cnvrt.coords using the new grconvert functions and they worked perfectly. I have already noted in the help page for cnvrt.coords (for the next version coming out soon) that people should start using grconvertX and grconvertY when they become available. Are there any more of the utilities in TeachingDemos that will be need to be depricated with the release of version 2.7? (I read through the current NEWS file, but are there any more planned?). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Wednesday, March 12, 2008 9:13 AM To: Tom La Bone Cc: r-help@r-project.org Subject: Re: [R] Specifying relative position of text in a plot See ?par, entry usr. Either set a new coordinate system and use it, or convert 1/10 to user coordinates. In R-devel (2.7.0 to be) this is easier: text(grconvertX(0.1,npc), grconvertY(0.5, npc), some text) cnvrt.coords() in package TeachingDemos does something similar (although it doesn't use the standard R names for coordinate systems, and there are more than 5). On Wed, 12 Mar 2008, Tom La Bone wrote: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. Tom -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ R-help@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. __ R-help@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.
Re: [R] Specifying relative position of text in a plot
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alberto Monteiro Sent: Wednesday, March 12, 2008 10:28 AM To: Tom La Bone; r-help@r-project.org Subject: Re: [R] Specifying relative position of text in a plot Tom La Bone asked: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. See the help of par: ?par Namely: plot(rnorm(100), rnorm(100)) pu - par()$usr x - pu[1] * 0.5 + pu[2] * 0.5 y - pu[3] * 0.1 + pu[4] * 0.9 text(x, y, the quick brown fox jumps over a lazy dog) Alberto Monteiro This is a useful example of placing text, but I interpreted the request as aking for the text to be placed at the left side of the graph (1/10 of the x range) and centered vertically (with respect to the y scale). So, then I would calculate x and y as x - pu[1] * 0.9 + pu[2] * 0.1 y - pu[3] * 0.5 + pu[4] * 0.5 Also, text() centers the supplied text at the x,y coordinates. So, if Tom wants the text begin at that point, he will need to adjust the x coordinate for the length of the string being printed. Hope this is helpful, Dan Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204 __ R-help@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.
Re: [R] Specifying relative position of text in a plot
To left justify the text rather than center, use the adj argument, this is easier and probably more reliable than trying to adjust the x coordinate manually. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nordlund, Dan (DSHS/RDA) Sent: Wednesday, March 12, 2008 12:26 PM To: Alberto Monteiro; Tom La Bone; r-help@r-project.org Subject: Re: [R] Specifying relative position of text in a plot -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alberto Monteiro Sent: Wednesday, March 12, 2008 10:28 AM To: Tom La Bone; r-help@r-project.org Subject: Re: [R] Specifying relative position of text in a plot Tom La Bone asked: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. See the help of par: ?par Namely: plot(rnorm(100), rnorm(100)) pu - par()$usr x - pu[1] * 0.5 + pu[2] * 0.5 y - pu[3] * 0.1 + pu[4] * 0.9 text(x, y, the quick brown fox jumps over a lazy dog) Alberto Monteiro This is a useful example of placing text, but I interpreted the request as aking for the text to be placed at the left side of the graph (1/10 of the x range) and centered vertically (with respect to the y scale). So, then I would calculate x and y as x - pu[1] * 0.9 + pu[2] * 0.1 y - pu[3] * 0.5 + pu[4] * 0.5 Also, text() centers the supplied text at the x,y coordinates. So, if Tom wants the text begin at that point, he will need to adjust the x coordinate for the length of the string being printed. Hope this is helpful, Dan Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204 __ R-help@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. __ R-help@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.
Re: [R] Specifying relative position of text in a plot
On Wed, 12 Mar 2008, Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alberto Monteiro Sent: Wednesday, March 12, 2008 10:28 AM To: Tom La Bone; r-help@r-project.org Subject: Re: [R] Specifying relative position of text in a plot Tom La Bone asked: What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. See the help of par: ?par Namely: plot(rnorm(100), rnorm(100)) pu - par()$usr x - pu[1] * 0.5 + pu[2] * 0.5 y - pu[3] * 0.1 + pu[4] * 0.9 text(x, y, the quick brown fox jumps over a lazy dog) Alberto Monteiro This is a useful example of placing text, but I interpreted the request as aking for the text to be placed at the left side of the graph (1/10 of the x range) and centered vertically (with respect to the y scale). So, then I would calculate x and y as x - pu[1] * 0.9 + pu[2] * 0.1 y - pu[3] * 0.5 + pu[4] * 0.5 Yes, and there has been another wrong answer earlier. Note that my suggestion of plot(rnorm(100), rnorm(100)) op - par(usr=c(0,1,0,1)) text(1/10, 1/2, some text) par(op) is a lot less error-prone (and it also works with log scales). Also, text() centers the supplied text at the x,y coordinates. So, if Tom wants the text begin at that point, he will need to adjust the x coordinate for the length of the string being printed. Better, use the adj= argument to text. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] Specifying relative position of text in a plot
Here is one way. ... usr - par(usr) # get user coordinates par(usr = c(0, 1, 0, 1)) # new relative user coordinates text(0.1, 0.5, Some text, adj = 0) # if that's what you want par(usr = usr) # restore original user coordinates ... If you were going to be doing this a lot, you could write a simple wrapper function to text(...) to incorporate this change to relative coordinates and back again. Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tom La Bone Sent: Thursday, 13 March 2008 12:34 AM To: r-help@r-project.org Subject: [R] Specifying relative position of text in a plot What is the simplest way to specify the location of text in a scatter plot (created using the plot function) in relative terms rather than specific x-y coordinates? For example, rather than putting text at (300,49) on a plot, how do I put it 1/10 of the way over from the y axis and 1/2 of the way up from the x axis? Thanks. Tom -- View this message in context: http://www.nabble.com/Specifying-relative-position-of-text-in-a-plot-tp1 6002549p16002549.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.