cranvas (version 0.8.5)

qmosaic: Mosaic plot. Create a mosaicplot using a formula (as described in prodplot)

Description

Interactive elements for mosaic plots are arrow keys for navigating through the mosaic hierarchy: arrow up reduces complexity of the mosaic by one variable, arrow down increases the complexity by one, if possible. Arrow left and right rotate a previously included variable into the last split position. Conditioning/Unconditioning is done with keys 'C' and 'U' Keys 'B' and 'S" switch to bar and spine representation, respectively Key 'R' rotates the last split variable between horizontal and vertical display.

Usage

qmosaic(data, formula, divider = productplots::mosaic(), cascade = 0, scale_max = TRUE, na.rm = FALSE, subset = NULL, colour = "grey30", main = NULL, ...)

Arguments

data
a mutaframe which is typically built upon a data frame along with several row attributes
formula
a formula to describe order in which variables go into the mosaicplot. The first variables are the ones visually most important, i.e. Y ~ X1 + X2 + X3 first splits according to X3, then according to X2, then according to X1
divider
structure of the split in each direction. Choices are "hbar", "vbar" for horizontal/vertical barcharts, "hspine", "vspine" for horizontal/vertical spineplots.
cascade
parameter for prodplot in package productplots
scale_max
parameter for prodplot in package productplots
na.rm
handling of missing values, defaults to FALSE
subset
parameter for prodplot -
colour
fill colour of rectangles - only used if colour is not used in the data
main
parameter for prodplot
...

Examples

Run this code
library(cranvas)
library(productplots)
library(plyr)


## Simpson on board the Titanic?!
data(Titanic)
titanic <- as.data.frame(Titanic)
titanic$Passenger <- titanic$Class != "Crew"
qtitanic <- qdata(titanic, color = Survived)

qtitanic$.brushed <- qtitanic$Survived == "Yes"
## passengers have a higher probability of survival than crew members ...
qmosaic(qtitanic, Freq ~ Passenger, divider = c("hspine"))
## unless sex is taken into account: the conditional association between Passenger
## and Survival changes to the opposite: both male and female crew members had
## better changes of survival than their counterparts on the passenger side.
qmosaic(qtitanic, Freq ~ Passenger | Sex, divider = c("hspine", "hspine"))

## this is an example of the Simpson's paradox, and is due to the strong
## association between crew membership and gender.
qmosaic(qtitanic, Freq ~ Sex + Passenger, divider = c("vspine", "hspine"))

####################### 
data(happy)
qhappy <- qdata(happy, color = happy)

qmosaic(qhappy, ~sex + marital, divider = c("vspine", "hspine"))
qmosaic(qhappy, ~marital + happy + year, divider = c("vspine", "hspine", "hspine"))
qmosaic(qhappy, ~marital + degree, divider = c("vspine", "hspine"))
qmosaic(qhappy, ~happy, divider = c("hbar"))

qbar(sex, qhappy)


qmosaic(qtitanic, Freq ~ Sex + Age + Class)
qbar(Survived, data = qtitanic)

qmosaic(qtitanic, Freq ~ Survived, "hbar")
qmosaic(qtitanic, Freq ~ Age, "hbar")
qmosaic(qtitanic, Freq ~ Sex, "hbar")
qmosaic(qtitanic, Freq ~ Class, "hbar")

qmosaic(qtitanic, Freq ~ Sex + Survived | Class, divider = c("vspine", "hspine", 
    "hspine"))
data(happy)
qhappy <- qdata(happy)
qmosaic(qhappy, ~happy, "hbar")
qmosaic(qhappy, ~happy + age, c("hspine", "vspine"))

cranvas_off()

Run the code above in your browser using DataCamp Workspace