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'?
On Fri, 9 Sep 2005, Larsen Chung 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.R comes with support for various time formats, use them! Look at particular at "chron" and "POSIXct". In addition, you might want to define a time series object which might make plotting (and other operations) even easier. Look in particular at the "zoo" package which supports both time formats above. Z> 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'? > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
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)