Skip to content
Prev 10507 / 15274 Next

XTS plot of intra-daily stock prices

Hi Costas,

Unfortunately, I think this isn't exactly a trivial thing to do: R
doesn't by default support broken axis plots (which I think is more or
less what you are looking for). I'm interested in helping you out with
this, but just to make sure I understand what you are looking for,
your data is something like

tm <- as.POSIXct(1342207451, origin = "1970-01-01")
x <- xts(rnorm(100), tm+ 100*c(0:49, 0:49 + 5e2))
plot(x)

and you want that long flat bit omitted?

Here's a cheap hack to work around if I understand the problem:

plot.by.day <- function(x, ...){
    ti <- deparse(substitute(x))
    x2 <- split(x, as.Date(index(x), tz = ""))
    op <- par(no.readonly = TRUE)
    par(mfrow = c(1, length(x2)), mar = c(5.1, 0, 4.1, 0), oma = c(0,
4.1, 1, 2.1))
    for(x3 in x2) xts::plot.xts(as.xts(x3), yaxt = "n", main = "",
ylim = range(x), ...)
    mtext(ti, outer = TRUE, cex = 2, line = -2)
}

It could use some more work though. (and I just wipped it up, so it
will probably break in all sorts of unpleasant ways) Lemme know how it
goes for you and I might start polishing it.

Best,
Michael
On Fri, Jul 13, 2012 at 1:50 PM, Costas Vorlow <costas.vorlow at gmail.com> wrote: