ploting time series

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

ploting time series

fernando
Please,
I am ploting a time series in which the x-axis are dates.
How to use the "segments" in this graph?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

Mark Knecht
On Sun, Nov 24, 2013 at 3:05 PM, fernando <[hidden email]> wrote:
> Please,
> I am ploting a time series in which the x-axis are dates.
> How to use the "segments" in this graph?
> Thanks
>


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

_______________________________________________
[hidden email] 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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

Patrick Burns-2
In reply to this post by fernando
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:

> Please,
> I am ploting a time series in which the x-axis are dates.
> How to use the "segments" in this graph?
> Thanks
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/ploting-time-series-tp4681085.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> [hidden email] 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.
>

--
Patrick Burns
[hidden email]
http://www.burns-stat.com
http://www.portfolioprobe.com/blog
twitter: @burnsstat @portfolioprobe

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

Michael Weylandt
In reply to this post by fernando
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 <[hidden email]> wrote:

> Please,
> I am ploting a time series in which the x-axis are dates.
> How to use the "segments" in this graph?
> Thanks
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/ploting-time-series-tp4681085.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> [hidden email] 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.

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

fernando
In reply to this post by Mark Knecht
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
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

Mark Knecht
On Tue, Nov 26, 2013 at 8:13 AM, fernando <[hidden email]> 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

_______________________________________________
[hidden email] 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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

daniel-2
In reply to this post by fernando
Fernando,

┬┐Could you send your sessionInfo()?

Daniel Merino



2013/11/26 fernando <[hidden email]>

> 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.
>
> _______________________________________________
> [hidden email] 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.
>


--
Daniel

        [[alternative HTML version deleted]]


_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ploting time series

daniel-2
In reply to this post by fernando
Fernando,

I gess that you locale is not english, try this:

lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
x <- c("1jan1997", "2jan1997", "3jan1997", "4jan1997")
y <- c(-.3, 0.2, -0.2, 0.3)
date <- as.Date(x, "%d%b%Y")
Sys.setlocale("LC_TIME", lct)
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
sessionInfo()

Daniel Merino


2013/11/26 fernando <[hidden email]>

> 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.
>
> _______________________________________________
> [hidden email] 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.
>



--
Daniel

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.