# NOT RUN {
#Standard use: Return standalone code for plotting a function:
visualize(c(1:10), "Variable 1", doEval = FALSE)
#Define a new visualization function and call it using visualize either
#using allVisual or a class specific argument:
mosaicVisual <- function(v, vnam, doEval) {
thisCall <- call("mosaicplot", table(v), main = vnam, xlab = "")
if (doEval) {
return(eval(thisCall))
} else return(deparse(thisCall))
}
mosaicVisual <- visualFunction(mosaicVisual,
description = "Mosaicplots from graphics",
classes = allClasses())
#Inspect all options for visualFunctions:
allVisualFunctions()
# }
# NOT RUN {
#set mosaicVisual for all variable types:
visualize(c("1", "1", "1", "2", "2", "a"), "My variable",
visuals = setVisuals(all = "mosaicVisual"))
#set mosaicVisual only for character variables:
visualize(c("1", "1", "1", "2", "2", "a"), "My variable",
visuals = setVisuals(character = "mosaicVisual"))
#this will use standardVisual, as our variable is not numeric:
visualize(c("1", "1", "1", "2", "2", "a"), "My variable",
visuals = setVisuals(numeric = "mosaicVisual"))
# }
# NOT RUN {
#return code for a mosaic plot
visualize(c("1", "1", "1", "2", "2", "a"), "My variable",
allVisuals = "mosaicVisual", doEval=FALSE)
# }
# NOT RUN {
#Produce multiple plots easily by calling visualize on a full dataset:
data(testData)
testData2 <- testData[, c("charVar", "factorVar", "numVar", "intVar")]
visualize(testData2)
#When using visualize on a dataset, datatype specific arguments have no
#influence:
visualize(testData2, setVisuals(character = "basicVisual",
factor = "basicVisual"))
#But we can still use the "all" argument in setVisuals:
visualize(testData2, visuals = setVisuals(all = "basicVisual"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab