#

library(vcd) library(SVGAnnotation) doc = svgPlot(m <- mosaic(~ gear + carb, data = mtcars, shade = TRUE))
g = xmlRoot(doc)[["g"]] xmlSize(g) names(g)
n = xmlSApply(g, xmlSize)
sapply(xmlChildren(g)[n == 1], getShape)

## Finding the Pieces

One approach is to save the SVG to a file and to modify some of the elements to color them, e.g., red and then view the document. We can then identify which element was changed. The mosaic plot

There are 31 elements within the top-level g element. The first is the background rectangle. The next two are the legend (the text and the shading box/rectangle). The next elements are the data regions/cells of the mosaic plot, i.e. the rectangles and lines illustrating empty cells. Then we have the axes labels and we end with the labels for the rows and columns.

``