[R] adding infrequent date labels to x-axis
Hrishi Mittal
hrishimittal at gmail.com
Mon Feb 22 19:36:18 CET 2010
Hi emorway,
You are right. I tried the command only with one year's data, in which case
it plots month names as labels. But for multiple years, the labels become
years. I found this old post useful -
http://n4.nabble.com/Month-tick-marks-on-a-plot-td879121.html#a879121.
Picking the code from the comment by Gavin Simson, I think this should work:
plot(as.Date(cropped.cast1$date,"%Y-%m-%d"),cropped.cast1$Frac_ET_Satsfd_mean,xaxt="n")
x<-as.Date(cropped.cast1$date,"%Y-%m-%d")
ticks.at <- seq(min(x), max(x), by = "months")
## format the labels as abbreviated month names
ticks.lab <- format(ticks.at, format = "%b")
## indicator variable; is month January?
m1 <- ticks.lab == "Jan"
## plot small ticks and labels for months not Jan
Axis(x, at = ticks.at[!m1], side = 1,
labels = ticks.lab[!m1], las = 2, cex.axis = 0.7)
## plot the default tick locations for years
Axis(x, side = 1, las = 2)
## add the box
box()
-----
Try http://prettygraph.com Pretty Graph , the easiest way to make R-powered
graphs on the web.
--
View this message in context: http://n4.nabble.com/adding-infrequent-date-labels-to-x-axis-tp1564804p1564924.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list