On 14-02-11 6:13 PM, Peter Lomas wrote:
Hello,

I'm creating graphs like the following:

x <- seq(as.POSIXct("2012-01-01"), as.POSIXct("2013-01-01"), by = "days")
y <- (1:length(x)*10 + cumsum(rnorm(n=length(x), mean=0, sd= 100)))
plot(x,y, type = 'l', xaxt='n')
axis.POSIXct(side=1,at=seq(min(x),  max(x), by="months"),  format = "%b
\'%y", labels = TRUE)

For aesthetic reasons, I would only like to print the year label (%y) on
the x axis at the change points of the year.  In this example, there would
be a "Jan '12" and "Jan '13" with the months in between omitting the year
label.

Any clues would be appreciated!

Instead of labels=TRUE, compute the strings for the labels you want, and use those. For example,

 ticks <- seq(min(x),  max(x), by="months")
 full <- format(ticks, format="%b \'%y")
 short <- format(ticks, format="%b")
 labels <- ifelse (short == "Jan", full, short)
 axis.POSIXct(side=1,at=ticks, labels = labels)

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to