Skip to content

ploting time series

8 messages · fernando, Patrick Burns, R. Michael Weylandt +2 more

#
On Sun, Nov 24, 2013 at 3:05 PM, fernando <faiube at gmail.com> wrote:
If you will provide R code for a very small example case then you'll
likely get an answer that works for you.

Cheers,
Mark
1 day later
#
My approach in your situation would be to
do the original plot command and then do:

par("usr")

This will return a length 4 vector of the
2 X limits and 2 Y limits that the graphics
system think are in place.  Those first
two numbers should tell you how R is thinking
and you can then adjust your thinking when
you use 'segments'.

Note that this only works with base graphics.
If you are using ggplot2 or grid graphics, then
you'll need a different approach.

Pat
On 24/11/2013 23:05, fernando wrote:

  
    
#
If you are using my xtsExtra::plot.xts or Jeff's xts::plot.xts, the plot engine uses POSIXct (unix epoch seconds) to align the x-axis; that sometimes throws folks off. Take a look at xtsExtra::lines.xts for an example. 

Michael
On Nov 24, 2013, at 18:05, 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.

Cheers



--
View this message in context: http://r.789695.n4.nabble.com/ploting-time-series-tp4681085p4681190.html
Sent from the Rmetrics mailing list archive at Nabble.com.
#
On Tue, Nov 26, 2013 at 8:13 AM, fernando <faiube at gmail.com> wrote:
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