[R] intraday plot and gaps in data

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jul 26 13:47:24 CEST 2011


On Tue, Jul 26, 2011 at 7:11 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Tue, Jul 26, 2011 at 4:48 AM, djdjoko <djdjoko at googlemail.com> wrote:
>> Hi,
>> I have an intraday timeseries of financial data (see below) which has gaps
>> due to market opening and closing hours. I am trying to plot it, but the
>> time gap is always visible in the plot. I tried converting data to xts, zoo,
>> timeSeries and plotting it with different functions i.e. plot.xts, plot.zoo.
>> The only way to make it work was with function 'chartSeries' in the quantmod
>> package which excludes non existing data from the plot.
>> I still would like to use the plot, plot.zoo or plot.xts functions if
>> possible.  I spent a lot of time looking through forums and could not find
>> anything that would help. Is this possible at all?
>>
>> Thanks
>>
>> 2009-09-08 20:40:00 169
>> 2009-09-08 20:45:00 170
>> 2009-09-08 20:50:00 170
>> 2009-09-08 20:55:00 170
>> 2009-09-09 07:00:00 175
>> 2009-09-09 07:05:00 176
>> 2009-09-09 07:10:00 176
>> 2009-09-09 07:15:00 176
>
> Perhaps something like this. First we read in the data and then plot
> an auxiliary series, z0, which is the same but with time points 1, 2,
> 3 and so on.  We suppress the X axis and add our own.
>
> Lines <- "2009-09-08 20:40:00 169
> 2009-09-08 20:45:00 170
> 2009-09-08 20:50:00 170
> 2009-09-08 20:55:00 170
> 2009-09-09 07:00:00 175
> 2009-09-09 07:05:00 176
> 2009-09-09 07:10:00 176
> 2009-09-09 07:15:00 176"
> library(zoo)
> z <- read.zoo(textConnection(Lines), index = 1:2, tz = "")
> z0 <- zoo(coredata(z))
> plot(z0, xaxt = "n")
> axis(1, time(z0), lab = format(time(z), "%d\n%Hh"), cex.axis = .7)
>

or perhaps this one in place of last line:

axis(1, time(z0), lab = format(time(z), "%d %H:%M"), cex.axis = .7,
tcl = .3, las = 3)



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list