Title: | Mosaic Plots in the 'ggplot2' Framework |
---|---|
Description: | Mosaic plots in the 'ggplot2' framework. Mosaic plot functionality is provided in a single 'ggplot2' layer by calling the geom 'mosaic'. |
Authors: | Haley Jeppson [aut, cre] , Heike Hofmann [aut] , Di Cook [aut] , Hadley Wickham [ctb] |
Maintainer: | Haley Jeppson <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3.4 |
Built: | 2024-11-14 05:45:55 UTC |
Source: | https://github.com/haleyjeppson/ggmosaic |
Template for a double decker plot. A double decker plot is composed of a sequence of spines in the same direction, with the final spine in the opposite direction.
ddecker(direction = "h")
ddecker(direction = "h")
direction |
direction of first split |
Data from the results of a SurveyMonkey survey commissioned by FiveThirtyEight for the story 41 Percent of Fliers Say It’s Rude To Recline Your Airplane Seat.
fly
fly
A data frame with 1040 rows and 27 variables:
Respondent ID
How often do you travel by plane?
Do you ever recline your seat when you fly?
How tall are you?
Do you have any children under 18?
n a row of three seats, who should get to use the two arm rests?
In a row of two seats, who should get to use the middle arm rest?
Who should have control over the window shade?
Is it rude to move to an unsold seat on a plane?
Generally speaking, is it rude to say more than a few words to the stranger sitting next to you on a plane?
On a six hour flight from NYC to LA, how many times is it acceptable to get up if you're not in an aisle seat?
Under normal circumstances, does a person who reclines their seat during a flight have any obligation to the person sitting behind them?
Is it rude to recline your seat on a plane?
Given the opportunity, would you eliminate the possibility of reclining seats on planes entirely?
Is it rude to ask someone to switch seats with you in order to be closer to friends?
Is it rude to ask someone to switch seats with you in order to be closer to family?
Is it rude to wake a passenger up if you are trying to go to the bathroom?
Is it rude to wake a passenger up if you are trying to walk around?
In general, is it rude to bring a baby on a plane?
In general, is it rude to knowingly bring unruly children on a plane?
Have you ever used personal electronics during take off or landing in violation of a flight attendant's direction?
Have you ever smoked a cigarette in an airplane bathroom when it was against the rules?
Gender
Age
Household Income
Education
Region
https://github.com/fivethirtyeight/data/tree/master/flying-etiquette-survey
A mosaic plot is a convenient graphical summary of the conditional distributions in a contingency table and is composed of spines in alternating directions.
geom_mosaic( mapping = NULL, data = NULL, stat = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, show.legend = NA, inherit.aes = FALSE, ... ) stat_mosaic_text( mapping = NULL, data = NULL, geom = "Text", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, ... ) stat_mosaic( mapping = NULL, data = NULL, geom = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, ... )
geom_mosaic( mapping = NULL, data = NULL, stat = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, show.legend = NA, inherit.aes = FALSE, ... ) stat_mosaic_text( mapping = NULL, data = NULL, geom = "Text", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, ... ) stat_mosaic( mapping = NULL, data = NULL, geom = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
divider |
Divider function. The default divider function is mosaic() which will use spines in alternating directions. The four options for partitioning:
|
offset |
Set the space between the first spine |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
other arguments passed on to |
geom |
The geometric object to use to display the data for this layer.
When using a
|
location of center of the rectangle
location of center of the rectangle
location of bottom left corner
location of bottom right corner
location of top left corner
location of top right corner
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived)) # good practice: use the 'dependent' variable (or most important variable) # as fill variable # if there is only one variable inside `product()`, # `product()` can be omitted ggplot(data = titanic) + geom_mosaic(aes(x = Class, fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class, Age), fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), conds = product(Age), fill = Survived)) # if there is only one variable inside `product()`, # `product()` can be omitted ggplot(data = titanic) + geom_mosaic(aes(x = Class, conds = Age, fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Survived, Class), fill = Age)) # Just excluded for timing. Examples are included in testing to make sure they work ## Not run: data(happy) ggplot(data = happy) + geom_mosaic(aes(x = product(happy)), divider="hbar") ggplot(data = happy) + geom_mosaic(aes(x = product(happy))) + coord_flip() # weighting is important ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(happy))) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy)) + theme(axis.text.x=element_text(angle=35)) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy), na.rm=TRUE) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health, sex, degree), fill=happy), na.rm=TRUE) # here is where a bit more control over the spacing of the bars is helpful: # set labels manually: ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset=0) + scale_x_productlist("Age", labels=c(17+1:72)) # thin out labels manually: labels <- c(17+1:72) labels[labels %% 5 != 0] <- "" ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset=0) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy, conds = product(sex)), divider=mosaic("v"), na.rm=TRUE, offset=0.001) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset = 0) + facet_grid(sex~.) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(happy, finrela, health)), divider=mosaic("h")) ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(happy, finrela, health)), offset=.005) # Spine example ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(health), fill = health)) + facet_grid(happy~.) ## End(Not run) # end of don't run
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived)) # good practice: use the 'dependent' variable (or most important variable) # as fill variable # if there is only one variable inside `product()`, # `product()` can be omitted ggplot(data = titanic) + geom_mosaic(aes(x = Class, fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class, Age), fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), conds = product(Age), fill = Survived)) # if there is only one variable inside `product()`, # `product()` can be omitted ggplot(data = titanic) + geom_mosaic(aes(x = Class, conds = Age, fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Survived, Class), fill = Age)) # Just excluded for timing. Examples are included in testing to make sure they work ## Not run: data(happy) ggplot(data = happy) + geom_mosaic(aes(x = product(happy)), divider="hbar") ggplot(data = happy) + geom_mosaic(aes(x = product(happy))) + coord_flip() # weighting is important ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(happy))) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy)) + theme(axis.text.x=element_text(angle=35)) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy), na.rm=TRUE) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health, sex, degree), fill=happy), na.rm=TRUE) # here is where a bit more control over the spacing of the bars is helpful: # set labels manually: ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset=0) + scale_x_productlist("Age", labels=c(17+1:72)) # thin out labels manually: labels <- c(17+1:72) labels[labels %% 5 != 0] <- "" ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset=0) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy, conds = product(sex)), divider=mosaic("v"), na.rm=TRUE, offset=0.001) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(age), fill=happy), na.rm=TRUE, offset = 0) + facet_grid(sex~.) + scale_x_productlist("Age", labels=labels) ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(happy, finrela, health)), divider=mosaic("h")) ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(happy, finrela, health)), offset=.005) # Spine example ggplot(data = happy) + geom_mosaic(aes(weight = wtssall, x = product(health), fill = health)) + facet_grid(happy~.) ## End(Not run) # end of don't run
A mosaic plat with jittered dots
geom_mosaic_jitter( mapping = NULL, data = NULL, stat = "mosaic_jitter", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, drop_level = FALSE, seed = NA, show.legend = NA, inherit.aes = FALSE, ... ) stat_mosaic_jitter( mapping = NULL, data = NULL, geom = "mosaic_jitter", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, drop_level = FALSE, seed = NA, ... )
geom_mosaic_jitter( mapping = NULL, data = NULL, stat = "mosaic_jitter", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, drop_level = FALSE, seed = NA, show.legend = NA, inherit.aes = FALSE, ... ) stat_mosaic_jitter( mapping = NULL, data = NULL, geom = "mosaic_jitter", position = "identity", na.rm = FALSE, divider = mosaic(), show.legend = NA, inherit.aes = TRUE, offset = 0.01, drop_level = FALSE, seed = NA, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
divider |
Divider function. The default divider function is mosaic() which will use spines in alternating directions. The four options for partitioning:
|
offset |
Set the space between the first spine |
drop_level |
Generate points for the max - 1 level |
seed |
Random seed passed to |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
other arguments passed on to |
geom |
The geometric object to use to display the data for this layer.
When using a
|
location of bottom left corner
location of bottom right corner
location of top left corner
location of top right corner
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived), alpha = 0.3) + geom_mosaic_jitter(aes(x = product(Class), color = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class)), alpha = 0.1) + geom_mosaic_jitter(aes(x = product(Class), color = Survived), drop_level = TRUE) ggplot(data = titanic) + geom_mosaic(alpha = 0.3, aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_jitter(aes(x = product(Class, Sex), color = Survived), divider = c("vspine", "hspine", "hspine")) ggplot(data = titanic) + geom_mosaic(alpha = 0.3, aes(x = product(Class), conds = product(Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_jitter(aes(x = product(Class), conds = product(Sex), fill = Survived), divider = c("vspine", "hspine", "hspine"))
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived), alpha = 0.3) + geom_mosaic_jitter(aes(x = product(Class), color = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class)), alpha = 0.1) + geom_mosaic_jitter(aes(x = product(Class), color = Survived), drop_level = TRUE) ggplot(data = titanic) + geom_mosaic(alpha = 0.3, aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_jitter(aes(x = product(Class, Sex), color = Survived), divider = c("vspine", "hspine", "hspine")) ggplot(data = titanic) + geom_mosaic(alpha = 0.3, aes(x = product(Class), conds = product(Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_jitter(aes(x = product(Class), conds = product(Sex), fill = Survived), divider = c("vspine", "hspine", "hspine"))
A mosaic plot with text or labels
geom_mosaic_text( mapping = NULL, data = NULL, stat = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, show.legend = NA, inherit.aes = FALSE, as.label = FALSE, repel = FALSE, repel_params = NULL, check_overlap = FALSE, ... )
geom_mosaic_text( mapping = NULL, data = NULL, stat = "mosaic", position = "identity", na.rm = FALSE, divider = mosaic(), offset = 0.01, show.legend = NA, inherit.aes = FALSE, as.label = FALSE, repel = FALSE, repel_params = NULL, check_overlap = FALSE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
divider |
Divider function. The default divider function is mosaic() which will use spines in alternating directions. The four options for partitioning:
|
offset |
Set the space between the first spine |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
as.label |
Show as a ggplot label (box with round corners) |
repel |
Use ggrepel wo labels don't overlap |
repel_params |
List of ggrepel parameters (e.g. list(point.padding = 0)) |
check_overlap |
If |
... |
other arguments passed on to |
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived)) + geom_mosaic_text(aes(x = product(Class), fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_text(aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine"), size = 2) ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE) # avoid overlapping text ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, check_overlap = TRUE) # or use ggrepel ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE) # and as a label ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE, as.label=TRUE)
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class), fill = Survived)) + geom_mosaic_text(aes(x = product(Class), fill = Survived)) ggplot(data = titanic) + geom_mosaic(aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine")) + geom_mosaic_text(aes(x = product(Class, Sex), fill = Survived), divider = c("vspine", "hspine", "hspine"), size = 2) ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE) # avoid overlapping text ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, check_overlap = TRUE) # or use ggrepel ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE) # and as a label ggplot(data = happy) + geom_mosaic(aes(x = product(health), fill = happy), na.rm = TRUE, show.legend = FALSE) + geom_mosaic_text(aes(x = product(happy, health)), na.rm = TRUE, repel = TRUE, as.label=TRUE)
Shiny app "EDA with Mosaic Plots" for interactive exploratory model building
ggmosaic_app(example = c("mosaics", "models"), ...)
ggmosaic_app(example = c("mosaics", "models"), ...)
example |
Selected shiny app to launch. |
... |
arguments passed on. |
The data is a small sample of variables related to happiness from the general social survey (GSS). The GSS is a yearly cross-sectional survey of Americans, run since 1972. We combine data for more than 25 years to yield over 60 thousand observations, and of the over 5,000 variables, we select some variables that are related to happiness:
data(happy)
data(happy)
A data frame with 62466 rows and 11 variables
year. year of the response, 1972 to 2018.
age. age in years: 18–89 (89 stands for all 89 year olds and older).
degree. highest education: lt high school, high school, junior college, bachelor, graduate.
finrela. how is your financial status compared to others: far below, below average, average, above average, far above.
happy. happiness: very happy, pretty happy, not too happy.
health. health: excellent, good, fair, poor.
marital. marital status: married, never married, divorced, widowed, separated.
sex. sex: female, male.
polviews. from extremely conservative to extremely liberal.
partyid. party identification: strong republican, not str republican, ind near rep, independent, ind near dem, not str democrat, strong democrat, other party.
wtssall. probability weight. 0.39–8.74
Horizontal bar partition: width constant, height varies.
hbar(data, bounds, offset = 0.02, max = NULL)
hbar(data, bounds, offset = 0.02, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Horizontal spine partition: height constant, width varies.
hspine(data, bounds, offset = offset, max = NULL)
hspine(data, bounds, offset = offset, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Template for a mosaic plot. A mosaic plot is composed of spines in alternating directions.
mosaic(direction = "h")
mosaic(direction = "h")
direction |
direction of first split |
Wrapper for a list
product(...)
product(...)
... |
Unquoted variables going into the product plot. |
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Survived, Class), fill = Survived))
data(titanic) ggplot(data = titanic) + geom_mosaic(aes(x = product(Survived, Class), fill = Survived))
Used internally to determine class of variable x
## S3 method for class 'productlist' scale_type(x)
## S3 method for class 'productlist' scale_type(x)
x |
variable |
character string "productlist"
Determining scales for mosaics
scale_x_productlist( name = ggplot2::waiver(), breaks = product_breaks(), minor_breaks = NULL, labels = product_labels(), limits = NULL, expand = ggplot2::waiver(), oob = scales::censor, na.value = NA_real_, transform = "identity", position = "bottom", sec.axis = ggplot2::waiver() ) scale_y_productlist( name = ggplot2::waiver(), breaks = product_breaks(), minor_breaks = NULL, labels = product_labels(), limits = NULL, expand = ggplot2::waiver(), oob = scales::censor, na.value = NA_real_, transform = "identity", position = "left", sec.axis = ggplot2::waiver() ) ScaleContinuousProduct
scale_x_productlist( name = ggplot2::waiver(), breaks = product_breaks(), minor_breaks = NULL, labels = product_labels(), limits = NULL, expand = ggplot2::waiver(), oob = scales::censor, na.value = NA_real_, transform = "identity", position = "bottom", sec.axis = ggplot2::waiver() ) scale_y_productlist( name = ggplot2::waiver(), breaks = product_breaks(), minor_breaks = NULL, labels = product_labels(), limits = NULL, expand = ggplot2::waiver(), oob = scales::censor, na.value = NA_real_, transform = "identity", position = "left", sec.axis = ggplot2::waiver() ) ScaleContinuousProduct
name |
set to pseudo waiver function |
breaks |
One of:
|
minor_breaks |
One of:
|
labels |
One of:
|
limits |
One of:
|
expand |
For position scales, a vector of range expansion constants used to add some
padding around the data to ensure that they are placed some distance
away from the axes. Use the convenience function |
oob |
One of:
|
na.value |
Missing values will be replaced with this value. |
transform |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
position |
For position scales, The position of the axis.
|
sec.axis |
specify a secondary axis |
An object of class ScaleContinuousProduct
(inherits from ScaleContinuousPosition
, ScaleContinuous
, Scale
, ggproto
, gg
) of length 5.
Spine partition: divide longest dimension.
spine(data, bounds, offset = offset, max = NULL)
spine(data, bounds, offset = offset, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Squeeze pieces to lie within specified bounds; directly copied from package productplots
squeeze(pieces, bounds = bound())
squeeze(pieces, bounds = bound())
pieces |
rectangle specified via l(eft), r(ight), b(ottom), t(op) |
bounds |
rectangle specified via l(eft), r(ight), b(ottom), t(op) |
re-scaled values for piece according to boundaries given by bounds
Hadley Wickham
Themes set the general aspect of the plot such as the colour of the
background, gridlines, the size and colour of fonts.
theme_mosaic
provides access to the regular ggplot2 theme, but removes any
background, most of the gridlines, and ensures an aspect ratio of 1 for better
viewing of the mosaics.
base_size |
base font size |
base_family |
base font family |
library(ggmosaic) data(happy) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy), na.rm=TRUE) + theme_mosaic()
library(ggmosaic) data(happy) ggplot(data = happy) + geom_mosaic(aes(weight=wtssall, x=product(health), fill=happy), na.rm=TRUE) + theme_mosaic()
A dataset containing some demographics and survival of people on board the Titanic
titanic
titanic
A data frame with 2201 rows and 4 variables:
factor variable containing the class of a passenger (1st, 2nd, 3rd) or crew.
Male/Female.
Child/Adult. This information is not very reliable, because it was inferred from boarding documents that did not state actual age in years.
Yes/No.
Vertical bar partition: height constant, width varies.
vbar(data, bounds, offset = 0.02, max = NULL)
vbar(data, bounds, offset = 0.02, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |
Vertical spine partition: width constant, height varies.
vspine(data, bounds, offset = offset, max = NULL)
vspine(data, bounds, offset = offset, max = NULL)
data |
bounds data frame |
bounds |
bounds of space to partition |
offset |
space between spines |
max |
maximum value |