简体   繁体   中英

How to add \bar{x} to an R plot

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.

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM