Learn R Programming

berryFunctions (version 1.9.0)

monthAxis: Label date axis

Description

monthAxis labels date axes at sensible intervals in the time region of weeks to decades.

Usage

monthAxis(side=1, startyear=NULL, stopyear=NULL, n=5, npm=NULL,
npy=NA, format="%d.%m.\n%Y", mgp=c(3,1.5,0), cex.axis=1, las=1, ...)

Arguments

side
Which axis are to be labeled? (can be several). DEFAULT: 1
startyear
Integer. starting year. DEFAULT: NULL = internally computed from par("usr")
stopyear
Ditto for ending year. DEFAULT: NULL
n
Approximate number of labels that should be printed (as in code{pretty}). DEFAULT: 5
npm
Number of labels per month, overrides n. DEFAULT: NULL = internally computed.
npy
Number of labels per year, overrides npm and n. DEFAULT: NA
format
Format of date, see details in strptime. DEFAULT: "%d.%m.\n%Y"
mgp
MarGinPlacement, see par. DEFAULT: c(3,1.5,0)
cex.axis
CharacterEXpansion (letter size). DEFAULT: 1
las
LabelAxisStyle for orientation of labels. DEFAULT: 1 (upright)
...
Further arguments passed to axis, like lwd, col.ticks, hadj, lty, ...

Value

  • The dates that were labelled

See Also

monthLabs for the numbercrunching itself, axis.Date with defaults that are less nice.

Examples

Run this code
set.seed(007) # for reproducibility
Date1 <- sort(as.Date("2013-09-25")+sample(0:150, 30))
plot(Date1, cumsum(rnorm(30)), type="l", xaxt="n", ann=FALSE)
monthAxis(1)
monthAxis(1, npm=2) # fix number of labels per month

Date2 <- sort(as.Date("2011-07-13")+sample(0:1400, 50))
plot(Date2, cumsum(rnorm(50)), type="l", xaxt="n", ann=FALSE)
monthAxis(1, format="")
monthAxis(1, npy=6) # fix number of labels per year

Date3 <- sort(as.Date("2011-07-13")+sample(0:1200, 50))
plot(Date3, cumsum(rnorm(50)), type="l", xaxt="n", ann=FALSE)
monthAxis(1, n=4, font=2)
monthAxis(1, col.axis=3) # too many labels with default n=5

Run the code above in your browser using DataLab