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.
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:
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
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:
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.
_______________________________________________ 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.
Patrick Burns patrick at burns-stat.com http://www.burns-stat.com http://www.portfolioprobe.com/blog twitter: @burnsstat @portfolioprobe
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:
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.
_______________________________________________ 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.
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:
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20131126/5cf8515e/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20131126/ddcebe1a/attachment.pl>