-3

I have a time series data that can plot using:

plot(x$numbers, type="l", col="blue")

I like to get the 95th percentile and add this 95th percentile to this graph

x_percent<-quantile(x$numbers, 0.95)

How do I add x_percent to the existing graph of x$numbers?

x$numbers<-c(1,2,3,8,10,30)
x$percent<-quantile(x$numbers, 0.95)
plot(x$numbers, type="l")

here, I like to add the x$percent to the graph, basically draw a vertical line with the value of 95th percentile value. andy ideas?

Sean Kaplan
  • 61
  • 2
  • 9
  • 1
    could you provide a sample of `x$numbers`, I am not sure what you mean by adding `x_percent`. Do you mean marking where the 95th precintile range is? – user1317221_G May 18 '12 at 14:24
  • I'm guessing... but I think you want `abline` however, I think you might not be plotting what you think you're plotting... – Justin May 18 '12 at 14:27
  • I just edited the original post. – Sean Kaplan May 18 '12 at 14:28
  • 1
    This still isn't reproducible since we don't have the `data.frame` x. however, my answer still holds. look at `?abline` – Justin May 18 '12 at 14:30
  • 2
    you may find this insightful: http://stackoverflow.com/questions/3494593/shading-a-kernel-density-plot-between-two-points – JD Long May 18 '12 at 15:01

1 Answers1

2

Ok your edit didnt help much but I am guessing you're wanting to do something like this..(see Justins comments)

x   <- seq(0,20,length=1000)
y   <- dnorm(x,mean=10, sd=3)
plot(x,y, type="l", lwd=2)
abline(a=1,b=1,v=1,lty=3)

But your mention of time series makes me think you're not sure what you're plotting. Otherwise you would be simply marking the abline on a particular date.

enter image description here

PS I'm guessing you do want the line on the other side of the x axis

strager
  • 88,763
  • 26
  • 134
  • 176
user1317221_G
  • 15,087
  • 3
  • 52
  • 78