tags:

views:

82

answers:

3

Hello,

I would like to name some points of a R graphic, got from the basic function plot().

More precisely I have a 2-dimensional parametric function t -> (a(t),b(t)), and I plot the points (a(t),b(t)). I would like to print the value of t corresponding to each point.

Thank you

+4  A: 

You can use text() as below:

 set.seed(10)
 x = rnorm(10)
 y = rnorm(10)

plot(y~x, pch = ".", cex = 2)
text(x, y, 
    label = paste("(", round(x, 1), ", ", round(y, 1), ")", sep = ""), 
    cex = 0.6)

If you don't want all of the points, just send some of them to text().

Greg
You could also add some other text (t, for example) to the labels = parameter of text()
Greg
Thanks it works well
Bossavy
+1  A: 

I don't dig t -> (a(t),b(t)) expression... nevermind, I figured out that you want to display values instead of plotting characters. Here goes:

# I'll steal shamelessly Greg's code
plot(x, y, pch = "")
# then do the text() part...

However, I recommend doing this with ggplot2:

ggplot(mtcars, aes(mpg, hp)) + geom_text(aes(label = rownames(mtcars)))

Unfortunately, I can't help you more with this one unless you come up with some dummy dataset.

aL3xa
A: 

In reply to the second half of your question,

"I have a 2-dimensional parametric function t -> (a(t),b(t)), and I plot the points (a(t),b(t)). I would like to print the value of t corresponding to each point."

The following example shows how a pair of parametric functions can be used to define the locations of points, as well as the argument of the function:

t <- seq(0,1.75,by=0.25)*pi
plot(cos(t),sin(t))
text(cos(t),sin(t),labels=round(t,2), ## location and text
     pos = 1,offset=0.4) ## text is placed below the specified locations
nullglob