[R] Question about plotting discontinuous data

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 9 21:58:55 CEST 2005


On 9/9/05, Larsen Chung <ychung4 at uiuc.edu> wrote:
> Hi, I have a simple question that I just cannot figure out. I
> have 2 corresponding columns of data, one column (X-axis) for
> time (formatted thus: 8:30:01am = 830.1, 12:30:05pm = 1230.5,
> and one column (Y-axis) for values.
> 
> When I attempt to plot the data using something like
> plot(inputdata[,1],inputdata[,2],type="l");
> I get breaks in the plot (since the time essentially jumps
> from 8:59:59am = 859.59 to 9:00:00am = 900.0).
> 
> Essentially, I get the plot shape I want if I just plot the
> 'values' column using plot(inputdata[,2],type="l");
> however, then I don't get the corresponding 'time' labels. Is
> there a way I can plot these two columns together without the
> 'breaks'?

Suppose this is your input data:

xx <- 11:12
tt <- c(830.1, 1230.5)

# use the times class in chron library
library(chron)
tt.times <- times(paste(tt %/% 100, floor(tt %% 100), (100 * tt) %%
100, sep = ":"))
plot(tt.times, xx)

# or represent it as a zoo object and plot that
library(zoo)
z <- zoo(xx, tt.times)
plot(z)




More information about the R-help mailing list