Description Usage Arguments Value Note Author(s) References See Also Examples
The function annotateMosaic
adds basic tooltips to a mosaic plot
for visualizing frequency tables and conditional probabilities.
The tooltips help viewers to comprehend what can be a complex
plot.
The tooltips currently give the count along with the different levels
of the categorical variables.
One can specify a function that is called to create the tooltip for
each cell.
Two lower level functions are getCategoryLabelNodes.mosaic
getAxesLabelNodes.mosaic
.
These return the SVG nodes corresponding to the
labels for each category on the different sides of the plot
and the SVG nodes for the axes/variable labels, respectively.
These functions annotate the SVG nodes with meta-informatio about the type. This allows us to retrieve the same nodes in subsequent calls even if we have modified the structure of the SVG document as we add markup such as tooltips and links.
Note that for the current implementation, if any "row" in the mosaic plot has all cells with zero observations, the subsequent tooltips will be mis-aligned, i.e. some of the latter tooltips will be for the wrong (earlier) cells.
1 2 3 4 5 6 7 8 | annotateMosaic(doc, table, cellTips = NULL,
axisLabelTips = c(names(attr(table, "col.vars")),
names(attr(table, "row.vars"))),
categoryTips = getMosaicLabels(table),
shade = FALSE, addCSS = TRUE)
getCategoryLabelNodes.mosaic(doc, table = NULL,
numCells = prod(dim(table)), groupZeros = NA)
getAxesLabelNodes.mosaic(doc, table = NULL, groupZeros = NA)
|
doc |
the SVG document, typically created via a call to
|
table |
the frequency table returned by the call to
|
axisLabelTips |
the text for the axes labels tooltips |
categoryTips |
tooltips for the labels on the axes that identify the different categories of each of the categorical variables. |
shade |
a logical value indicating whether the |
addCSS |
a logical value indicating whether to add the (default) CSS to the SVG document or the name of a CSS file or CSS content to add. |
cellTips |
a character vector of tool tips for the cells in the
plot or a function that is called to compute the tooltip string for a
given cell. If this is a function it will be called with a single
argument which is a data frame with one row giving the levels of the
different categorical variables along with a variable named
|
numCells |
the number of cells in the mosaic plot. This can be
specified instead of the |
groupZeros |
a logical value (or |
The updated SVG document.
At present, we can only handle mosaic plots with less than 5 variables.
Duncan Temple Lang
The vcd
package.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | if(require(vcd)) {
a = matrix(as.integer(rnorm(12, 100, 10)), 3, 4, dimnames = list(c("A", "B", "C"), c("W", "X", "Y", "Z")))
names(dimnames(a)) = c("Var 1", "Var 2")
saveXML(annotateMosaic(svgPlot(o <- mosaic(a)), o), "simpleMosaic.svg")
saveXML(annotateMosaic(svgPlot( m <- mosaic(UCBAdmissions)), m), "ucb.svg")
saveXML(annotateMosaic(svgPlot(z <- mosaic(Survived ~ ., data = Titanic)), z), "titanic.svg")
# Example of 4 variables with more than 2 categories.
xx = data.frame(a = sample(1:3, 100, TRUE), b = sample(c("A", "B", "C", "D"), 100, TRUE),
c = sample(c("X", "Y"), 100, TRUE), d = sample(c("Yes", "No"), 100, TRUE))
saveXML(annotateMosaic(svgPlot(m <- mosaic(with(xx, table(a, b, c, d)))), m), "multiMosaic.svg")
# Provide a function for creating the cell tooltip strings.
saveXML(annotateMosaic(svgPlot(o <- mosaic(a)), o, cellTips = function(x) x$.count), "mySimpleMosaic.svg")
# annotate the plot more manually, i.e. specifying links and
# tooltips for the axes labels and category labels.
data(UCBAdmissions)
doc = svgPlot( m <- mosaic(UCBAdmissions))
cats = getCategoryLabelNodes.mosaic(doc, m)
ax <- getAxesLabelNodes.mosaic(doc, m)
# annotateMosaic(doc, m, categoryTips = character())
mapply(addLink, ax,
c("http://www.math.yorku.ca/SCS/vcd/",
"http://cran.r-project.org/web/packages/vcd/index.html",
"http://www.omegahat.org/SVGAnnotation"))
tips = c(Rejected = "The applicant was not admitted this year",
Admitted = "The applicant was admitted ",
F = "Department of ...",
E = "Department of ...",
D = "Department of ...",
C = "Department of ...",
B = "Department of ...",
A = "Department of ...",
Male = "Applicant was a man",
Female = "Applicant was a woman")
addToolTips(cats, tips[names(cats)])
saveXML(doc, "iucb.svg")
} else {
warning("You need the vcd package (Visualizing Categorical Data) for these mosaic examples")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.