[R-SIG-Finance] plotting vertical lines on months in xyplot

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Mar 16 04:27:38 CET 2011


Hi Worik,

I hope this doesn't come across as picky, but I cannot restrain myself
from improving your simple example.

On Tue, Mar 15, 2011 at 9:47 PM, Worik <worik.stanton at gmail.com> wrote:
> I have a similar problem as Jeff had back in the day.  I want to put a
> vertical line on a plot
>
> There must be a way....
>
> Simple example:
>
> library(xts)
> v <- vector()
> v[1] <- 10
> for(i in 2:100){
>  v[i] <- v[i-1]+rnorm(1, 0, 0.01)
> }

Growing vectors like this is slow.  rnorm() is vectorized.  Take
advantage of that.
V <- cumsum(c(10,rnorm(99,0,0.01)))

> X <- xts(v, seq(as.Date("2009-01-01"), by=1, length.out=100))
> plot(X)
>
> ## Try to put a vertical line in....
> abline(v=X[50,])
> abline(v=50)
> abline(v=index(X)[50])
>
>
>
> --
> If we amplify everything, we hear nothing.
> --
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>


--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-SIG-Finance mailing list