1

There is a point x=3.1234,y=5.6789, the command points(x,y) adds the point to a plot. I'd like to add some notations to this points on the plot.

version 1: (3.12,5.68)

version 2: line1 ~ $(\bar(x),\bar(y))$, line2 ~ $\bar(x)=3.1234, \bar(y)=5.6789$

Which means that if the number is not too long or we can display them with fixed digits, then I'd like the immediate numbers be displayed within the brackets. Otherwise I'd like it to be displayed in two lines, where the first lines says "the coordinate is mean of x and mean of y" while the second line explains what excat values are these two means.

I tried variants of the command: text(x,y-0.2,bquote(list(.(x) , .(y)))); text(x,y-0.2,bquote(list(.(bar(x)) , .(bar(y)))));, etc.

But none of them worked good. I really appreciate if some can diaplay at least one version of the above formats.

user3813057
  • 891
  • 3
  • 13
  • 31
  • not sure what you want, this? `x <- y <- 1:5; plot(x, y); text(x, y, parse(text = sprintf("bar(%s)~','~bar(%s)", x, y)), pos = 1)` – rawr Sep 06 '15 at 22:25
  • not certain if you are using plot() or ggplot() but [here](http://stackoverflow.com/questions/15624656/labeling-points-in-geom-point-graph-in-ggplot2) is a method of adding labels to some points, where I think you would just replace PTS>24 with PTS=3.12 – Shawn Mehan Sep 07 '15 at 00:03

1 Answers1

2

I'm not sure about the best way to display multi-line annotations. If you stick to a single line you can get a pretty readable annotation using:

xs = ys = 1:10 
x = 3.2
y = 4.6
plot(xs, ys)
text(x, y - 0.2, 
     bquote("(" * bar(x) * " = " * .(x) * ", " *  bar(y) * " = " * .(y) * ")")
)

Producing:

enter image description here

Marius
  • 58,213
  • 16
  • 107
  • 105