Try this:
plot(tsData, ylab="Values", xlab="Zeit", xaxt =
"n")
axis(1, time(tsData), rep(substr(month.abb, 1, 1), length = length(tsData)),
cex.axis = .3, tcl = -.5)
jan <- time(tsData)[cycle(tsData) == 1] # january
axis(1, jan, FALSE, tcl = -1)
abline(v = jan, lty = 2)
and also look at the example with main = "Fancy X Axis" in
library(zoo)
?plot.zoo
example(plot.zoo)
On Mon, Sep 8, 2008 at 3:03 PM, KarstenW <K.Weinert at gmx.net>
wrote:>
> Hello,
> how is it possible to plot a time series of monthly data over several years
> such that the x-axis shows the first letter of the month and displays a
grid
> line at every year? I am new to R and had no real success until now. I
have:
>
>> library(utils)
>> oneMonth = 1.0 / 12.0
>> tsData = ts(rnorm(103,100), start=2000, deltat=oneMonth) # goes until
Jul
>> 2008, real data
>> plot(tsData, ylab="Values", xlab="Zeit",
axes=FALSE)
>> axis(2) # as is
>> atX=seq(from=time(tsData)[1], to=time(tsData)[length(tsData)],
>> by=oneMonth)
>> labMonths=
c("J","F","M","A","M","J","J","A","S","O","N","D")
>> labX = rep(labMonths, length.out=length(tsData))
>> axis(1, at=atX, label=labX)
>
> But here I am stuck. First, I do not know how to add the years. And then, I
> would like to show all the labels, but only few of the months are
displayed.
>
> Any hint appreciated,
> kind regards,
> Karsten.
> --
> View this message in context:
http://www.nabble.com/Time-Series-x-axis-labeling-tp19378906p19378906.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>