2013-02-15 15 views
5

पर डेटा पॉइंट्स के तीर लेबलिंग को मैं इंडेक्स के साथ डेटा पॉइंट लेबल करना चाहता हूं - दृश्य परीक्षा द्वारा आसानी से इंडेक्स नंबर की पहचान करने के लिए।आर प्लॉट

तो उदाहरण के लिए

,

x<-ts.plot(rnorm(10,0,1)) # would like to visually identify the data point indices easily through arrow labelling 
बेशक

, इस को प्राप्त करने का एक बेहतर तरीका है, पैकेज TeachingDemos से

+0

सभी जवाब सराहना करते हैं! सभी के लिए धन्यवाद एन वोट –

उत्तर

4

के लिए text() उपयोग कर सकते हैं आप arrows फ़ंक्शन का उपयोग कर सकते हैं:

set.seed(1); ts.plot(x <-rnorm(10,0,1), ylim=c(-1.6,1.6)) # some random data 
arrows(x0=1:length(x), y0=0, y1=x, code=2, col=2, length=.1) # adding arrows 
text(x=1:10, y=x+.1, 0, labels=round(x,2), cex=0.65) # adding text 
abline(h=0) # adding a horizontal line at y=0 

enter image description here

3

उपयोग my.symbols का सुझाव तीर स्थानों आप चाहते हैं की ओर इशारा करते प्राप्त करने के लिए कृपया:

require(TeachingDemos) 
d <- rnorm(10,0,1) 
plot(d, type="l", ylim=c(min(d)-1, max(d)+1)) 
my.symbols(x=1:10, y=d, ms.arrows, angle=pi/2, add=T, symb.plots=TRUE, adj=1.5) 

enter image description here

2

आप इस

n <- 10 
d <- rnorm(n) 
plot(d, type="l", ylim=c(min(d)-1, max(d)+1)) 
text(1:n, d+par("cxy")[2]/2,col=2) # Upside 
text(1:n, d-par("cxy")[2]/2,col=3) # Downside 
1

यहाँ एक lattice संस्करण, कुछ आधार समारोह के अनुरूप देखने के लिए।

set.seed(1234) 
dat = data.frame(x=1:10, y = rnorm(10,0,1)) 
xyplot(y~x,data=dat, type =c('l','p'), 
     panel = function(x,y,...){ 
     panel.fill(col=rgb(1,1,0,0.5)) 
     panel.xyplot(x,y,...) 
     panel.arrows(x, y0=0,x1=x, y1=y, code=2, col=2, length=.1) 
     panel.text(x,y,label=round(y,2),adj=1.2,cex=1.5) 
     panel.abline(a=0) 

     }) 

enter image description here

संबंधित मुद्दे