Hi to all, I have some problems to get the times-scale to the x-axis the times are coming from an excel sheet f. e [1] "0:01:00" "0:02:00" "0:03:00" "0:04:00" "0:05:00" "0:06:00" "0:07:00" [8] "0:08:00" "0:09:00" "0:10:00" "0:11:00" "0:12:00" "0:13:00" "0:14:00" [15] "0:15:00" "0:16:00" "0:17:00" "0:18:00" "0:19:00" "0:20:00" "0:21:00" [22] "0:22:00" "0:23:00" "0:24:00" "0:25:00" "0:26:00" "0:27:00" "0:28:00" [29] "0:29:00" "0:30:00" "0:31:00" "0:32:00" "0:33:00" "0:34:00" "0:35:00" [36] "0:36:00" "0:37:00" "0:38:00" "0:39:00" "0:40:00" "0:41:00" "0:42:00" [43] "0:43:00" "0:44:00" "0:45:00" "0:46:00" "0:47:00" "0:48:00" "0:49:00" [50] "0:50:00" I found the solution from tread http://finzi.psych.upenn.edu/R/Rhelp02a/archive/71234.html with an very good result: /> ># test data / /> >tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03", / /> >"23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", "23:55:03", / /> >"23:55:03") / /> >x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, / /> >0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) / /> > / /> >library(zoo) / /> >library(chron) / /> >z <- zoo(x, times(tt)) / /> >plot(z) / /> > / but I am unable to use the axis command for that issue: how could I change the axis(1, xaxp=c(0,50,5),font=2) that I will get a changeable amount of x-axis entries with a time format hr:min par(cex=1.2,lwd=1) range(x <- c(0,50)) range(y <- c(0,10)) plot(x,y, type="n",adj=0, asp=0, xlab="", ylab="",axes=FALSE,font.axis=2) axis(1, xaxp=c(0,50,5),font=2) axis(2, 0:10,font=2) box() Thank`s in advance Carmen
Try this: plot(z, xaxt = "n") xt <- paste("23", seq(5, 50, 5), sep = ":") axis(1, times(paste(xt, 0, sep = ":")), xt) On 11/8/06, Carmen Meier <carmei3 at web.de> wrote:> Hi to all, > I have some problems to get the times-scale to the x-axis the times are > coming from an excel sheet f. e > [1] "0:01:00" "0:02:00" "0:03:00" "0:04:00" "0:05:00" "0:06:00" "0:07:00" > [8] "0:08:00" "0:09:00" "0:10:00" "0:11:00" "0:12:00" "0:13:00" "0:14:00" > [15] "0:15:00" "0:16:00" "0:17:00" "0:18:00" "0:19:00" "0:20:00" "0:21:00" > [22] "0:22:00" "0:23:00" "0:24:00" "0:25:00" "0:26:00" "0:27:00" "0:28:00" > [29] "0:29:00" "0:30:00" "0:31:00" "0:32:00" "0:33:00" "0:34:00" "0:35:00" > [36] "0:36:00" "0:37:00" "0:38:00" "0:39:00" "0:40:00" "0:41:00" "0:42:00" > [43] "0:43:00" "0:44:00" "0:45:00" "0:46:00" "0:47:00" "0:48:00" "0:49:00" > [50] "0:50:00" > > I found the solution from tread > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/71234.html > with an very good result: > /> ># test data / > /> >tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03", / > /> >"23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", > "23:55:03", / > /> >"23:55:03") / > /> >x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, / > /> >0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) / > /> > / > /> >library(zoo) / > /> >library(chron) / > /> >z <- zoo(x, times(tt)) / > /> >plot(z) / > /> > / > but I am unable to use the axis command for that issue: > how could I change the axis(1, xaxp=c(0,50,5),font=2) that I will > get a changeable amount of x-axis entries with a time format hr:min > > par(cex=1.2,lwd=1) > range(x <- c(0,50)) > range(y <- c(0,10)) > plot(x,y, type="n",adj=0, asp=0, xlab="", > ylab="",axes=FALSE,font.axis=2) > axis(1, xaxp=c(0,50,5),font=2) > axis(2, 0:10,font=2) > box() > > > > Thank`s in advance > > Carmen > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >
Thank you for your reply Gabor, sure, the manually written axis works fine in any configuration. but I would prefer an "automatic" input. That means that I would like to use the datafield[1] for the minimum time and the datafield[max] (means the last one) for the maximum time. divided into x steps.The datafiled size could reach more than 7000 sec. With regards Carmen Gabor Grothendieck schrieb:> Try this: > > plot(z, xaxt = "n") > xt <- paste("23", seq(5, 50, 5), sep = ":") > axis(1, times(paste(xt, 0, sep = ":")), xt) > >> >> I have some problems to get the times-scale to the x-axis the times are >> coming from an excel sheet f. e >> [1] "0:01:00" "0:02:00" "0:03:00" "0:04:00" "0:05:00" "0:06:00" >> "0:07:00" >> [8] "0:08:00" "0:09:00" "0:10:00" "0:11:00" "0:12:00" "0:13:00" >> "0:14:00" >> [15] "0:15:00" "0:16:00" "0:17:00" "0:18:00" "0:19:00" "0:20:00" >> "0:21:00" >> [22] "0:22:00" "0:23:00" "0:24:00" "0:25:00" "0:26:00" "0:27:00" >> "0:28:00" >> [29] "0:29:00" "0:30:00" "0:31:00" "0:32:00" "0:33:00" "0:34:00" >> "0:35:00" >> [36] "0:36:00" "0:37:00" "0:38:00" "0:39:00" "0:40:00" "0:41:00" >> "0:42:00" >> [43] "0:43:00" "0:44:00" "0:45:00" "0:46:00" "0:47:00" "0:48:00" >> "0:49:00" >> [50] "0:50:00" >>
Is the problem how to produce an axis with a given minimum tick, maximum tick and given number of ticks? In that case try this (if not explain further): # input data # z is from original example mn <- times("23:00:00") mx <- times("23:55:00") n <- 12 xt <- times(seq(mn, mx, length = n)) plot(z, xaxt = "n") axis(1, xt, sub(":00$", "", xt)) If this is not what you want please explain further. On 11/8/06, Carmen Meier <carmei3 at web.de> wrote:> Thank you for your reply Gabor, > sure, the manually written axis works fine in any configuration. > but I would prefer an "automatic" input. > That means that I would like to use the datafield[1] for the minimum > time and the datafield[max] (means the last one) for the maximum time. > divided into x steps.The datafiled size could reach more than 7000 sec. > > With regards Carmen > > Gabor Grothendieck schrieb: > > Try this: > > > > plot(z, xaxt = "n") > > xt <- paste("23", seq(5, 50, 5), sep = ":") > > axis(1, times(paste(xt, 0, sep = ":")), xt) > > > >> > >> I have some problems to get the times-scale to the x-axis the times are > >> coming from an excel sheet f. e > >> [1] "0:01:00" "0:02:00" "0:03:00" "0:04:00" "0:05:00" "0:06:00" > >> "0:07:00" > >> [8] "0:08:00" "0:09:00" "0:10:00" "0:11:00" "0:12:00" "0:13:00" > >> "0:14:00" > >> [15] "0:15:00" "0:16:00" "0:17:00" "0:18:00" "0:19:00" "0:20:00" > >> "0:21:00" > >> [22] "0:22:00" "0:23:00" "0:24:00" "0:25:00" "0:26:00" "0:27:00" > >> "0:28:00" > >> [29] "0:29:00" "0:30:00" "0:31:00" "0:32:00" "0:33:00" "0:34:00" > >> "0:35:00" > >> [36] "0:36:00" "0:37:00" "0:38:00" "0:39:00" "0:40:00" "0:41:00" > >> "0:42:00" > >> [43] "0:43:00" "0:44:00" "0:45:00" "0:46:00" "0:47:00" "0:48:00" > >> "0:49:00" > >> [50] "0:50:00" > >> > >
Gabor Grothendieck schrieb:> Is the problem how to produce an axis with a given minimum tick, > maximum tick and given number of ticks? In that case try thisyes but ... ;-) I started with an plain R gui library(zoo) library(chron) # input data # z is from original example mn <- times("23:00:00") mx <- times("23:55:00") n <- 12 z <-(1:50) xt <- times(seq(mn, mx, length = n)) plot(z, xaxt = "n") axis(1, xt, sub(":00$", "", xt)) The result is an X-axes with 23:00 at the left side nothing else at the x-axis That`s just the same problem as I got with further trials of my own and a minor problem will be sub(":00$", "", xt)) if times(seq(mn, mx, length = n)) will not result xx:yy:00 values only (f.e n=17) Regards Carmen
My understanding is that the main point of your post was how to get times on the X axis. hopefully at this point its clear how to do that and you can come up with some algorithm to put whatever points you want on. Here is a slight generalization although you will likely have to generalize it further.> library(zoo) > library(chron) > tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03",+ "23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", "23:55:03", + "23:55:03")> x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571,+ 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972)> z <- zoo(x, times(tt)) > mn <- times("23:00:00") > mx <- times("23:55:00") > n <- 12 > xt <- times(seq(mn, mx, length = n)) > xt <- times(unique(sub("..$", "00", xt))) > plot(z, xaxt = "n") > axis(1, xt, sub(":00$", "", xt)) > R.version.string[1] "R version 2.4.0 Patched (2006-10-24 r39722)"> packageDescription("zoo")$Version[1] "1.2-1"> packageDescription("chron")$Version[1] "2.3-9">On 11/8/06, Carmen Meier <carmei3 at web.de> wrote:> Gabor Grothendieck schrieb: > > Is the problem how to produce an axis with a given minimum tick, > > maximum tick and given number of ticks? In that case try this > yes but ... ;-) > I started with an plain R gui > > library(zoo) > library(chron) > # input data > # z is from original example > mn <- times("23:00:00") > mx <- times("23:55:00") > n <- 12 > z <-(1:50) > xt <- times(seq(mn, mx, length = n)) > plot(z, xaxt = "n") > axis(1, xt, sub(":00$", "", xt)) > > > The result is an X-axes with 23:00 at the left side nothing else at the > x-axisNot for me. It gives ticks all along the x axis for me. I have placed the entire self contained code above just to be sure.> That`s just the same problem as I got with further trials of my own > and a minor problem will be sub(":00$", "", xt)) if > times(seq(mn, mx, length = n)) will not result > xx:yy:00 values only (f.e n=17) > > Regards Carmen >
Gabor Grothendieck schrieb:> My understanding is that the main point of your post was how to get times > on the X axis. hopefully at this point its clear how to do that and > you can > come up with some algorithm to put whatever points you want on.That?s right thank you> > Here is a slight generalization although you will likely have to > generalize > it further. .....this code works fine - just I was looking for> >> library(zoo) >> library(chron) >> tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03", > + "23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", > "23:55:03", > + "23:55:03") >> x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571, > + 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972) >> z <- zoo(x, times(tt)) ....................>> Gabor Grothendieck schrieb: >> > Is the problem how to produce an axis with a given minimum tick, >> > maximum tick and given number of ticks? In that case try this >> yes but ... ;-) >> I started with an plain R gui >> >> library(zoo) >> library(chron) >> # input data >> # z is from original example >> mn <- times("23:00:00") >> mx <- times("23:55:00") >> n <- 12 >> z <-(1:50) >> xt <- times(seq(mn, mx, length = n)) >> plot(z, xaxt = "n") >> axis(1, xt, sub(":00$", "", xt)) >> >> >> The result is an X-axes with 23:00 at the left side nothing else at the >> x-axis > > Not for me. It gives ticks all along the x axis for me. I have placed > the entire self contained code above just to be sure.This one (above) does not work R.version.string [1] "R version 2.4.0 (2006-10-03)" > packageDescription("chron")$Version [1] "2.3-9" Regards Carmen
You indicated that one of the solutions did not work for you but I am not clear which one you were referring to. To avoid confusion I have deleted all my and your comments except for the following which works for me if I paste it into a fresh session using Edit | Paste commands only menu in Windows XP:> library(zoo) > library(chron)> tt <- c("23:05:02", "23:10:02", "23:15:03", "23:20:03", "23:25:03",+ "23:30:03", "23:35:03", "23:40:03", "23:45:04", "23:50:04", "23:55:03", + "23:55:03")> x <- c(0.575764, 0.738379, 0.567414, 0.663436, 0.599834, 0.679571,+ 0.88141, 0.868848, 0.969271, 0.878968, 0.990972, 0.990972)> z <- zoo(x, times(tt))> mn <- times("23:00:00") > mx <- times("23:55:00") > n <- 12> xt <- times(seq(mn, mx, length = n))> xt <- times(unique(sub("..$", "00", xt)))> plot(z, xaxt = "n") > axis(1, xt, sub(":00$", "", xt))> R.version.string[1] "R version 2.4.0 Patched (2006-10-24 r39722)"> packageDescription("zoo")$Version[1] "1.2-1"> packageDescription("chron")$Version[1] "2.3-9"
Yes this one works, but (sorry) in the OP there was a plot without data to define the range So I tried to use your working suggestion in that manner: library(zoo) library(chron) time <- c("2:25:00","2:26:00","2:27:00","2:28:00","2:29:00","2:30:00","2:31:00", "2:32:00","2:33:00","2:34:00","2:35:00","2:36:00","2:37:00","2:38:00", "2:39:00","2:40:00","2:41:00","2:42:00","2:43:00","2:44:00","2:45:00", "2:46:00","2:47:00","2:48:00","2:49:00","2:50:00","2:51:00","2:52:00", "2:53:00","2:54:00","2:55:00","2:56:00","2:57:00","2:58:00","2:59:00", "3:00:00","3:01:00","3:02:00","3:03:00","3:04:00","3:05:00","3:06:00", "3:07:00","3:08:00","3:09:00","3:10:00","3:11:00","3:12:00","3:13:00", "3:14:00") min_time <- min(times(time)) max_time <- max(times(time)) duration <- max_time-min_time h <- hours(duration) # not nessesary here m <- minutes(duration) par(cex=1.2,lwd=1) range(x <- c(0,m)) #50 minutes range(y <- c(0,10)) plot(x,y, type="n",adj=0, asp=0, xlab="", ylab="",axes=FALSE,font.axis=2) # axis(1, 0:m,font=2) # works fine but not with times #---------- your suggestion -------- mn <- times(min_time) mx <- times(max_time) n <- 5 xt <- times(seq(mn, mx, length = n)) xt <- times(unique(sub("..$", "00", xt))) axis(1, xt, sub(":00$", "", xt)) # works only with plot data before #---------------------- axis(2, 0:10,font=2) box() Maybe you could explain the difference Best regards Carmen
Your code plots x which has nothing to do with xt. On 11/8/06, Carmen Meier <carmei3 at web.de> wrote:> Yes this one works, but (sorry) in the OP there was a plot without data > to define the range > So I tried to use your working suggestion in that manner: > > library(zoo) > library(chron) > time <- > c("2:25:00","2:26:00","2:27:00","2:28:00","2:29:00","2:30:00","2:31:00", > > "2:32:00","2:33:00","2:34:00","2:35:00","2:36:00","2:37:00","2:38:00", > > "2:39:00","2:40:00","2:41:00","2:42:00","2:43:00","2:44:00","2:45:00", > > "2:46:00","2:47:00","2:48:00","2:49:00","2:50:00","2:51:00","2:52:00", > > "2:53:00","2:54:00","2:55:00","2:56:00","2:57:00","2:58:00","2:59:00", > > "3:00:00","3:01:00","3:02:00","3:03:00","3:04:00","3:05:00","3:06:00", > > "3:07:00","3:08:00","3:09:00","3:10:00","3:11:00","3:12:00","3:13:00", > "3:14:00") > min_time <- min(times(time)) > max_time <- max(times(time)) > > duration <- max_time-min_time > h <- hours(duration) # not nessesary here > m <- minutes(duration) > par(cex=1.2,lwd=1) > range(x <- c(0,m)) #50 minutes > range(y <- c(0,10)) > plot(x,y, type="n",adj=0, asp=0, xlab="", > ylab="",axes=FALSE,font.axis=2) > # axis(1, 0:m,font=2) # works fine but not with times > > #---------- your suggestion -------- > mn <- times(min_time) > mx <- times(max_time) > n <- 5 > > xt <- times(seq(mn, mx, length = n)) > > xt <- times(unique(sub("..$", "00", xt))) > > axis(1, xt, sub(":00$", "", xt)) # works only with plot data before > #---------------------- > axis(2, 0:10,font=2) > box() > > > Maybe you could explain the difference > > Best regards Carmen >
Gabor Grothendieck schrieb:> Your code plots x which has nothing to do with xt. >The same result if you change xt to x: 02:25 at the origin nothing else - I do not know why #---------- your suggestion -------- mn <- times(min_time) mx <- times(max_time) n <- 12 t <- times(seq(mn, mx, length = n)) t <- times(unique(sub("..$", "00", t))) axis(1, x, sub(":00$", "", x)) # works only with plot data before Regards Carmen