2010-06-28 56 views
3

我想從基本函數plot()中得到一個R圖形的某些點。 (a(t),b(t)),並繪製點(a(t),b(t))。我想打印每個點對應的t的值。R圖形的命名點

謝謝

回答

5

您可以用文字(),如下:

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) 

如果你不希望所有的點,只是給他們中的一些文字()。

+0

您還可以添加某些其他文本(噸,例如)標籤=參數的文本() – Greg 2010-06-28 20:30:09

+0

謝謝它運作良好 – Bossavy 2010-06-29 07:59:04

1

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

不幸的是,我不能幫你多用這一個,除非你想出一些虛擬的數據集。

0

在回答您的問題的第二半,

「我有一個2維參數 功能噸 - >(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