Dear List, I am trying to plot date vs. time, but am having problems getting my y-axis labels how I want them.? When left on its own R plots time at 6 hour intervals from 03:00 to 23:00.? I am wanting 6 hour intervals from 2:00 to 22:00.? I realize yaxp doesn't work in plot(), so I am trying to get it to work in par().? However, now I get the ticks where I want them but the time is output as a very big number (serial time?).? I have also tried axis() using at= and also get seriel time numbers.? Any suggestions on how to format time on an axis? ? mydat$Date<-as.POSIXct(as.character(mydat$Date), format=c("%m/%d/%Y")) ? mydat$Time<-as.POSIXct(as.character(mydat$Time), format=c("%H:%M:%S")) ? plot(mydat$DateTime,mydat$Time, xlab=c("Date"), ylab=c("Time"), ? xlim=c(min(mydat$DateTime),max(mydat$DateTime)), ? ylim=c(min(mydat$Time),max(mydat$Time)), ? yaxt="n", ? yaxs="i", ? pch=19, cex=.4, ? type="n") ? par(yaxp=c(as.POSIXct(as.character("02:00"), format=c("%H:%M")),as.POSIXct(as.character("22:00"), format=c("%H:%M")),5)) ? axis(2) Thanks, Tim ?Tim Clark Marine Ecologist National Park of American Samoa
Two things I see. First is that par needs to be called _before_ the plot (although its effects will persist if you need to keep hacking away) and the second is that yaxp is expecting numeric arguments (which you are offering) but in your case these will need to be the numeric values in a Date-aligned version of those DateTimes used in your mydat arguments. POSIXct is the number of seconds since the origin. -- David. On Oct 11, 2010, at 6:56 PM, Tim Clark wrote:> Dear List, > > I am trying to plot date vs. time, but am having problems getting my > y-axis > labels how I want them. When left on its own R plots time at 6 hour > intervals > from 03:00 to 23:00. I am wanting 6 hour intervals from 2:00 to > 22:00. I > realize yaxp doesn't work in plot(), so I am trying to get it to > work in par(). > However, now I get the ticks where I want them but the time is > output as a very > big number (serial time?). I have also tried axis() using at= and > also get > seriel time numbers. Any suggestions on how to format time on an > axis? > > mydat$Date<-as.POSIXct(as.character(mydat$Date), format=c("%m/%d/ > %Y")) > mydat$Time<-as.POSIXct(as.character(mydat$Time), format=c("%H:%M: > %S")) > > plot(mydat$DateTime,mydat$Time, xlab=c("Date"), ylab=c("Time"), > xlim=c(min(mydat$DateTime),max(mydat$DateTime)), > ylim=c(min(mydat$Time),max(mydat$Time)), > yaxt="n", > yaxs="i", > pch=19, cex=.4, > type="n") > > par(yaxp=c(as.POSIXct(as.character("02:00"), > format=c("%H:%M")),as.POSIXct(as.character("22:00"), format=c("%H: > %M")),5)) > axis(2) > > > Thanks, > > Tim > Tim Clark > > Marine Ecologist > National Park of American Samoa > > > > > ______________________________________________ > R-help at r-project.org 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.David Winsemius, MD West Hartford, CT
use 'axis' with 'at=' and 'labels=' to put your own labels on the axis. Have to guess at your data since you did not provide a reproducible example: x <- seq(as.POSIXct('2010-10-11 00:00'), as.POSIXct('2010-10-12 00:00'), length = 20) plot(x, x, type = 'o', yaxt = 'n') axis.POSIXct(2, at = seq(as.POSIXct('2010-10-11 02:00'), as.POSIXct('2010-10-12 00:00'), by = '6 hours')) On Mon, Oct 11, 2010 at 6:56 PM, Tim Clark <mudiver1200 at yahoo.com> wrote:> Dear List, > > I am trying to plot date vs. time, but am having problems getting my y-axis > labels how I want them.? When left on its own R plots time at 6 hour intervals > from 03:00 to 23:00.? I am wanting 6 hour intervals from 2:00 to 22:00.? I > realize yaxp doesn't work in plot(), so I am trying to get it to work in par(). > However, now I get the ticks where I want them but the time is output as a very > big number (serial time?).? I have also tried axis() using at= and also get > seriel time numbers.? Any suggestions on how to format time on an axis? > > ? mydat$Date<-as.POSIXct(as.character(mydat$Date), format=c("%m/%d/%Y")) > ? mydat$Time<-as.POSIXct(as.character(mydat$Time), format=c("%H:%M:%S")) > > ? plot(mydat$DateTime,mydat$Time, xlab=c("Date"), ylab=c("Time"), > ? xlim=c(min(mydat$DateTime),max(mydat$DateTime)), > ? ylim=c(min(mydat$Time),max(mydat$Time)), > ? yaxt="n", > ? yaxs="i", > ? pch=19, cex=.4, > ? type="n") > > ? par(yaxp=c(as.POSIXct(as.character("02:00"), > format=c("%H:%M")),as.POSIXct(as.character("22:00"), format=c("%H:%M")),5)) > ? axis(2) > > > Thanks, > > Tim > ?Tim Clark > > Marine Ecologist > National Park of American Samoa > > > > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Apparently Analagous Threads
- yaxp problem for more irregular time series in one plot
- Control statements with condition with greater than one should give error (not just warning) [PATCH]
- graphical parameters in plot
- boxplot of different colors
- How to compute "yaxp" and "usr" without plotting ?