[R] time series plot: x-axis problem

Rui Barradas ruipbarradas at sapo.pt
Fri Apr 26 11:25:46 CEST 2013


Hello,

Try the following.

(rr=ts(rr,start=c(2012,5),frequency=12))

plot(rr, xlab="2012 - 2013", ylab="event freq", xaxt = "n", col="blue")

labs <- format(as.Date(time(rr)), "%b-%Y")

axis(1, time(rr), labs,	cex.axis = .9, tcl = -.5, las = 2)


Hope this helps,

Rui Barradas

Em 25-04-2013 19:11, Jerry escreveu:
> Hi,
>
> I'm trying to plot a simple time series. I'm running into an issue with
> x-axis
>
> The codes below will produce a plot with correct x-axis showing from Jan to
> Dec
>
>> rr=c(3,2,4,5,4,5,3,3,6,2,4,2)
>
>> (rr=ts(rr,start=c(2012,1),frequency=12))
>
>> win.graph(width=6.5, height=2.5,pointsize=8)
>
>> plot(rr, xlab="2012", ylab="event freq", xaxt = "n", col="blue")
>
>> axis(1, time(rr), rep(substr(month.abb, 1, 3), length = length(rr)),
> cex.axis = .9, tcl = -.5, las = 2)
>
>
> However, if I change the start point from Jan 2012 to May 2012, which is
>
>> (rr=ts(rr,start=c(2012,5),frequency=12))
>
>
> Then run the codes below
>
>> plot(rr, xlab="2012 - 2013", ylab="event freq", xaxt = "n", col="blue")
>
>> axis(1, time(rr), rep(substr(month.abb, 1, 3), length = length(rr)),
> cex.axis = .9, tcl = -.5, las = 2)
>
>
> In the the new plot produced, x-axis is still showing from Jan to Dec, not
> from May to April as I desired.
>
> How to fix x-axis? Is it possible to fix it WITHOUT modifying the object
> "rr"? Also, ideally, I would like to have each time point on x-axis showing
> month/year, not just month. How to do that?
>
> Any help and input will be much appreciated!
>
> Thanks
> Jerry
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list