[R] ticks on the Time Axis
Gabor Grothendieck
ggrothendieck at myway.com
Tue Aug 17 06:53:54 CEST 2004
Laura Holt <lauraholt_983 <at> hotmail.com> writes:
:
: Dear R People:
:
: I have the following montly time series
: >ya.ts
: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
: 2001 3.7 -0.8 0.3 -1.5 -0.2 -0.4 2.5 -1.0 -1.2 -1.2 0.4 -0.5
: 2002 0.5 0.0 -0.8 -1.0 0.6 0.8 -0.5 -2.4 1.3 1.4 -0.1 0.5
: >plot(ya.ts)
:
: When the plot is constructed, the ticks on the horizontal (time) axis are
: 2001.0, 2001.5, and so on.
:
: Is there a way to set up ticks such as J,F,M,A,M......by months, please?
This is not quite what you are asking for since the months are in
numbers (Jan = 01) and it may print only every third month if its
too cramped but its easy (no messing with axes) and it may be good
enough. It uses the fact that the chron package will plot numeric
months and years.
require(chron)
ya.start.date <- chron("1/1/1")
ya.dates <- seq(ya.start.date, length = length(ya.ts), by = "month")
plot(ya.dates, ya.ts)
If you want to automatically construct ya.start.date above from ya.ts,
use the fact that year-month-day character format is accepted by Date to
get the start date as a Date, convert that to chron and then use that in
place of the ya.start.date <- line above:
ya.start.date <- chron(as.Date(paste(c(start(ya.ts),1), collapse="-")))
More information about the R-help
mailing list