Hello,
Em 26-04-2013 14:30, arun escreveu:
Hi,
labs <- format(as.Date(time(rr)), "%b-%Y")
#Error in as.Date.default(time(rr)) :
# do not know how to convert 'time(rr)' to class “Date”
#I guess this needs library(zoo)
You're right, I forgot because it was already loaded prior to running
the code. Apologies to the OP.
Rui Barradas
library(zoo)
labs <- format(as.Date(time(rr)), "%b-%Y")
sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-unknown-linux-gnu (64-bit)
#or
z<- zoo(rr)
lab1<-as.yearmon(index(z))
plot(rr, xlab="2012 - 2013", ylab="event freq", xaxt = "n", col="blue")
axis(1, time(rr), lab1, cex.axis = .9, tcl = -.5, las = 2)
A.K.
----- Original Message -----
From: Rui Barradas <ruipbarra...@sapo.pt>
To: Jerry <i89...@gmail.com>
Cc: r-help@r-project.org
Sent: Friday, April 26, 2013 5:25 AM
Subject: Re: [R] time series plot: x-axis problem
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@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.
______________________________________________
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.
______________________________________________
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.