R 图形的命名点

发布于 2024-09-07 04:18:51 字数 150 浏览 3 评论 0原文

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

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝影如岚 2024-09-14 04:18:51

您可以按如下方式使用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()。

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().

狼性发作 2024-09-14 04:18:51

我不挖掘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)))

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

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.

北斗星光 2024-09-14 04:18:51

回答你问题的后半部分,

“我有一个二维参数
函数 t -> (a(t),b(t)),我绘制
点 (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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文