[R] X-axis with POSIXct dates

Jim_Garrett@bd.com Jim_Garrett at bd.com
Wed Sep 19 22:44:53 CEST 2001

I have a series of datasets, each containing pH measurements and
manufacturing dates, and each dataset pertains to a different manufactured
product.  I'm trying to create a series of plots of pH measurements by
date, but the default X-axis labeling behavior is not giving adequate
results in this particular case, and I can't figure out how to persuade R
to come up with something more meaningful.  Specifically, the datasets
generally span about 1.5 years, and only January 1 is given a tick mark and
label.  Some datasets contain both Jan. 1 2000 and Jan. 1 2001, and others
just Jan. 1 2001, so I'm getting one or two tick marks.  Generally every
month is represented in these datasets, and I would like to see a tick mark
every two or three months.  I can't seem to find a graceful way to do this.

System info:  Windows NT 4.0, 450 MHz Pentium II (I think), R version

Here is a small subset of data which reproduces the undesired default
behavior on my system:

> test.dat
        man.date First.Bottle.pH
X14   2000-03-08            9.74
X4241 2000-08-04            9.42
X4542 2000-12-07            8.54
X350  2001-02-05            9.51
X4591 2001-02-05            8.47
X4716 2001-02-07            9.54
X4933 2001-03-19            9.63
X2831 2001-04-19            9.70
X1068 2001-04-23            9.65
X1914 2001-05-23            9.98

"man.date" is of class POSIXct.


> plot(test.dat$man.date, test.dat$First.Bottle.pH)

yields a plot with a single X-axis tick mark and label at Jan. 1, 2001, as I said.  I dabbled with the "axis.POSIXct" function,
especially with the format option, but couldn't coerce it to plot more tick marks.  For example,

> axis.POSIXct(1, test.dat$man.date, "%m %d, %Y")

creates a tick mark and date label in the desired format, but only at Jan. 1, 2001.  In other words, It controls what the label looks like,
but not the number and spacing of labeled tick marks.

Any ideas would be appreciated!

Jim Garrett
Becton Dickinson Diagnostic Systems
Baltimore, Maryland, USA

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list