# NOT RUN {
#some trivial data
a <- 1:10
## Example 1
## Simple plot with cex handling
myplot1 <- function(x, y, z = NULL, cex = NULL,
cex.range = NULL, ...){
#set cex
cex <- cexHandler(z, cex, cex.range)
#plot
xyplot(y~x, cex = cex,...)
}
myplot1(a, a, a)
# compare
# }
# NOT RUN {
myplot1(a, a) #like plot(x, y)
myplot1(a, a, a*100) #as myplot1(a, a, a)
#because cex scaled by range
myplot1(a, b, c,
cex.range = c(1,5)) #cex range reset
myplot1(a, b, c,
cex.range = c(10,50),
cex = 1) #cex supersedes all else if supplied
# }
# NOT RUN {
## Example2
## plot function using lists/listUpdates
myplot2 <- function(x, y, z = NULL, ...){
#my default plot
default.args <- list(x = y~x, z = z,
pch = 20, cex = 4)
#update with whatever user supplied
plot.args <- listUpdate(default.args, list(...))
#col Management
plot.args$col <- do.call(colHandler, plot.args)
do.call(xyplot, plot.args)
}
#with colorkey based on z case
myplot2(a, a, a)
# compare
# }
# NOT RUN {
myplot2(a, b, c,
col.regions = "Blues") #col.regions recoloring
myplot2(a, b, c,
col = "red") ##but (again) col supersedes if supplied
# }
# NOT RUN {
# Note:
# See also example in ?listUpdate
# }
Run the code above in your browser using DataLab