Hi there, I have draw a scatter plot. Now, I hope to label the points in the plot. For example: plot(1:10) text(1:10, 1:10, LETTERS[1:10]) In the above line, I can set position for each labels with pos, e.g.: text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE)) as what you have seen, the length of pos can be longer than 1. in the above case, it has the length 10. However, I can not set offset with length longer than 1. The following code always set the offset to 0.1 rather than 0.1, 0.2, ..., 1 for the 10 labels. text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE), offset = seq(0.1, 1, 0.1)) it seems that adj also can not be set for multiple points with different values. Any hints? Thanks in advance. Regards, Jinsong
You can use the mapply function (or Vectorize) to call text with multiple values for arguments that only take a single value, like adj and offset. On Thu, Oct 3, 2013 at 10:48 AM, Jinsong Zhao <jszhao@yeah.net> wrote:> Hi there, > > I have draw a scatter plot. Now, I hope to label the points in the plot. > For example: > > plot(1:10) > text(1:10, 1:10, LETTERS[1:10]) > > In the above line, I can set position for each labels with pos, e.g.: > > text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE)) > > as what you have seen, the length of pos can be longer than 1. in the > above case, it has the length 10. > > However, I can not set offset with length longer than 1. The following > code always set the offset to 0.1 rather than 0.1, 0.2, ..., 1 for the 10 > labels. > > text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE), > offset = seq(0.1, 1, 0.1)) > > it seems that adj also can not be set for multiple points with different > values. > > Any hints? Thanks in advance. > > Regards, > Jinsong > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]
On 03/10/2013 12:48 PM, Jinsong Zhao wrote:> Hi there, > > I have draw a scatter plot. Now, I hope to label the points in the plot. > For example: > > plot(1:10) > text(1:10, 1:10, LETTERS[1:10]) > > In the above line, I can set position for each labels with pos, e.g.: > > text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE)) > > as what you have seen, the length of pos can be longer than 1. in the > above case, it has the length 10. > > However, I can not set offset with length longer than 1. The following > code always set the offset to 0.1 rather than 0.1, 0.2, ..., 1 for the > 10 labels. > > text(1:10, 1:10, LETTERS[1:10], pos = sample(1:4, 10, replace = TRUE), > offset = seq(0.1, 1, 0.1)) > > it seems that adj also can not be set for multiple points with different > values. > > Any hints? Thanks in advance.See ?text: those parameters apply to all text. To get what you want, call text() 10 times (e.g. in a loop, or in lapply). Duncan Murdoch