0

I have the following two dimensional data points, the first column is data ID

ID    V1              V2
1   -9.2523712  1.751943612
2   -0.9799493  0.067998776
3   -0.9799493  0.067998776
4   3.2156859   1.088934239
5   3.4915597   1.097911743
6   3.4915597   1.097911743
7   -0.9799493  0.067998776
8   -0.9799493  0.067998776
9   -0.9799493  0.067998776
10  3.2156859   1.088934239

Assume this array is named as fit, I plot these points as plot(fit[,2],fit[,3]) However, is that possible to mark each point with its ID on the plot? In addition, for some specific point, like ID 10, I would like to mark it with red color. How can I do that in R?

bit-question
  • 3,733
  • 17
  • 50
  • 63
  • possible duplicate of [Plot with conditional colors based on values in R](http://stackoverflow.com/questions/11838278/plot-with-conditional-colors-based-on-values-in-r) and [setting-the-color-for-an-individual-data-point](http://stackoverflow.com/questions/8774002/setting-the-color-for-an-individual-data-point) – mnel Jul 08 '13 at 04:20
  • Your points are all essentially on top of one another. It might be worth looking here too: http://stackoverflow.com/questions/7611169/intelligent-point-label-placement-in-r – thelatemail Jul 08 '13 at 04:38

2 Answers2

0

after your plot command, use the following:

text(x=fit[, 2], y=fit[, 3], labels=fit[, 1])
points(x=fit[fit$ID==10, 2], y=fit[fit$ID==10, 3], col="red")

That being said, much nicer in ggplot

Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178
0

Try jittering the points using letters[i] to label the ith point and superimpose that on a sunflower plot whose red spokes show multiplicities. We can play with the random seed and jitter parameters to tweak it. Point a has no overlaid points but there are five overlaid (b, c, g, h, i) near the bottom and there are four overlaid (d, e, f, j) near the right side as we can see from the plot.

set.seed(19)
fitj <- transform(fit, V1 = jitter(V1, 10), V2 = jitter(V2), 10)
with(fit, sunflowerplot(V1, V2))
with(fitj, text(V1, V2, letters[1:10]))

screenshot

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341