Unable to plot a decent x-Axis in a time series plot using zoo

April 7, 2011

[This article was first published on Greg's Research » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I use the R package zoo to plot a yearly time series of weekly averaged data. The problem is that my date variable (m.all$date) contains week numbers and these are plotted as x-Axis. What I would rather like to to is plot abbreviated months.

I can suppress the x-Axis in the plot using xaxt = "n" in the plot.zoo command, but cannot define a suitable x-Axis that plot abbreviated months instead.

I tried several variations of the axis.Date() commands without luck!

# Create zoo object for time series plot
z < - zoo(cbind(m.all$obsTPM, m.all$modTPM, m.all$refTPM), m.all$date)
names(z) <- c("Observation","Model estimate", "Model reference")
# Plot
plot.zoo(z[, 1], type = "l", lwd = 1, col = "black", screens = c(1), xlab = "Date (2005)", ylim=c(m.all$obsTPM,m.all$modTPM, m.all$refTPM), ylab = "Concentration (pg m-3)", main = "Alert TPM: Observations vs. Model Estimates, Weekly Means")
lines(z[, 2], lty = 5, lwd = 1, col = "blue")
lines(z[, 3], lty = 3, lwd = 1, col = "red")
legend("topleft", lty = c(1,5,3), legend = colnames(z), bty = "n", col = c("black","blue","red"), lwd = 1)

To leave a comment for the author, please follow the link and comment on their blog: Greg's Research » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , ,

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)