TeachingDemos (version 2.10)

cal: Plot a month or year calendar

Description

Plot a calendar of the specified year or month. Monthly calendars can have additional information (text/plots) added to the individual cells.

Usage

cal(month, year)

Arguments

month

The month for the calendar, if ommitted will do a yearly calendar, can either be a number from 1 to 12 or a character string that will be matched (using pmatch) against month.name.

year

The year for the calendar. If ommitted and month is an integer less than or equal to 12 then month will be used as the year.

Value

Nothing is returned when a whole year calendar is created. When the month calendar is created a function is returned invisibly that if passed an integer corresponding to a day of the month will set the graphics parameters so the corresponding day in the calendar becomes the current plotting figure. See the examples below.

Details

This function plots on the current (or default) graphics device a yearly or monthly calendar. It tries to guess what you want, if both year and month are ommitted then it will plot the current month. If month is an integer greater than 12 and no year is specified then that value will be used as the year for a yearly calendar. The month can be either an integer from 1 to 12 or a character string that will be matched against month.name using pmatch.

Each day of the monthly calendar is a plotting frame that can be added to using stardard low level functions, the coordinates of the plotting region (the entire box) are from 0 to 1 in both dimensions. The updateusr function can be used to change the coordinates. The return from the function (when creating a monthly calendar) can be used to select the day.

See Also

Sys.time, as.POSIXlt, par, updateusr

Examples

Run this code
# NOT RUN {
cal(2011)

cal('May')

setday <- cal(11, 2011)

setday(3)
text(0.5,0.5, 'Some\nCentered\nText')

setday(8)
text(1,1,'Top Right',adj=c(1,1))

setday(18)
text(0,0,'Bottom Left', adj=c(0,0) )

setday(21)
tmp.x <- runif(25)
tmp.y <- rnorm(25, tmp.x, .1)
mrgn.x <- 0.04*diff(range(tmp.x))
mrgn.y <- 0.04*diff(range(tmp.y))
updateusr( 0:1, 0:1, range(tmp.x)+c(-1,1)*mrgn.x, range(tmp.y)+c(-1,1)*mrgn.y)
points(tmp.x, tmp.y)

setday(30)
tmp <- hist(rnorm(100), plot=FALSE)
updateusr( 0:1, 0:1, range(tmp$breaks), range(tmp$counts*1.1,0) )
lines(tmp)
# }

Run the code above in your browser using DataCamp Workspace