Donnerstag, 5. November 2009

Add a time axis


Adding a time scaled x-axis to a plot can be tedious...

# add a time axis
axis(side = 1, at  =as.numeric(seq(as.Date("2000-01-01"), by = "year", length = 10))
  , labels = format( seq(as.Date("2000-01-01"), by = "year", length = 10) , "%Y")
  , cex.axis = 0.8, las = 1)

# plot the timegrid
# vertical gridlines according to chosen time-values
abline(v = seq(as.Date("2000-01-01"), by = "year", length = 10), col = "grey", lty = "dotted")
# where to plot the horizontal gridlines? get the coords by means of axTicks()
abline(h = axTicks(2), col = "grey", lty = "dotted")

Keine Kommentare: