我想为从基本函数plot()
得到的R
图形命名一些点。
更具体地说,我有一个二维参数函数t -> (a(t),b(t)),并且我绘制了点(a(t),b(t))。我想打印出对应于每个点的t值。
谢谢
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)
我不太理解 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 <- 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