ploting time series
On Tue, Nov 26, 2013 at 8:13 AM, fernando <faiube at gmail.com> wrote:
Hi Mark,
An example would be the following code
x <- c("1jan1997", "2jan1997", "3jan1997", "4jan1997")
y <- c(-.3, 0.2, -0.2, 0.3)
date <- as.Date(x, "%d%b%Y")
plot(date,y, type="l", ylim=c(-0.32,0.32))
segments(1,-.2,4,-.2) # I want a segment from Thu through Sat at y = -0.2
Thanks in advance.
It looks to me like the function segments is looking for groups of 4
values which you did set up, but that your first and third values
aren't 'dates' like the chart. Likely this means it's creating a
segment but it's off your chart somewhere in space.
Converting your 2nd & 4th dates appears to draw a segment from
Thursday to Saturday. I painted it read to make it move visible.
x <- c("1jan1997", "2jan1997", "3jan1997", "4jan1997")
y <- c(-.3, 0.2, -0.2, 0.3)
date <- as.Date(x, "%d%b%Y")
plot(date,y, type="l", ylim=c(-0.32,0.32))
#segments(1,-.2,4,-.2) # I want a segment from Thu through Sat at y = -0.2
segments(as.Date("2jan1997", "%d%b%Y"),-.2,
as.Date("4jan1997", "%d%b%Y"),-.2, col='red') # I want a
segment from Thu through Sat at y = -0.2
Hope this helps,
Mark