

Please,
I am ploting a time series in which the xaxis are dates.
How to use the "segments" in this graph?
Thanks


On Sun, Nov 24, 2013 at 3:05 PM, fernando < [hidden email]> wrote:
> Please,
> I am ploting a time series in which the xaxis 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/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.
markknecht@gmail.com


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:

Patrick Burns
[hidden email]
http://www.burnsstat.comhttp://www.portfolioprobe.com/blogtwitter: @burnsstat @portfolioprobe
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


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 xaxis; 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:
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


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


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/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.
markknecht@gmail.com


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/plotingtimeseriestp4681085p4681190.html> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions
> should go.
>

Daniel
[[alternative HTML version deleted]]
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


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/plotingtimeseriestp4681085p4681190.html> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions
> should go.
>

Daniel
[[alternative HTML version deleted]]
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.

