Graphics R图的命名点

Graphics R图的命名点,graphics,r,Graphics,R,我想命名从基本函数plot()得到的R图形的一些点 更准确地说,我有一个二维参数函数 t->(a(t),b(t)),然后我绘制点(a(t),b(t))。我想打印每个点对应的t值 谢谢您可以按如下方式使用text(): 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),

我想命名从基本函数plot()得到的R图形的一些点

更准确地说,我有一个二维参数函数 t->(a(t),b(t)),然后我绘制点(a(t),b(t))。我想打印每个点对应的t值

谢谢

您可以按如下方式使用text():

 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)
如果您不需要所有的点,只需将其中一些点发送到text()。

我不挖掘
t->(a(t),b(t))
表达式。。。没关系,我发现你想显示值而不是打印字符。下面是:

# I'll steal shamelessly Greg's code
plot(x, y, pch = "")
# then do the text() part...
但是,我建议使用
ggplot2

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

不幸的是,除非你拿出一些虚拟数据集,否则我无法在这方面为你提供更多帮助。

在回答你问题的后半部分时

“我有一个二维参数化模型 函数t->(a(t),b(t))和I绘图 点(a(t),b(t)),我想 打印对应的t值 每一点。”

以下示例显示如何使用一对参数化函数定义点的位置以及函数的参数:

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

t您还可以向text()的labels=参数添加一些其他文本(例如,t)