View source: R/plot_state_frequencies.R
| plot_mosaic | R Documentation |
Low-level rectangle-coordinate builder for marimekko (mosaic) plots.
Column widths are proportional to the per-column total of weight;
within each column, segments stack to height 1 with sub-heights
proportional to each row's share of that column's total.
plot_mosaic(
data,
x,
y,
weight,
fill = "y",
colors = NULL,
show_labels = TRUE,
label_size = 3.5,
x_label = NULL,
y_label = NULL
)
data |
A data.frame in long form. Must contain the columns named
in |
x |
Column name for the X (column) variable. |
y |
Column name for the Y (segment) variable. |
weight |
Column name for the cell weight (e.g. count). |
fill |
Either |
colors |
Optional character vector of fill colors. When
|
show_labels |
If |
label_size |
Numeric size for segment labels. |
x_label, y_label |
Optional axis labels. |
Used internally by plot_state_frequencies; exposed so that
other plot methods (e.g. permutation-residual visualisations) can reuse
the same geometry by supplying a different fill column.
A ggplot object.
df <- data.frame(
group = rep(c("A", "B", "C"), each = 3),
state = rep(c("s1", "s2", "s3"), 3),
count = c(10, 5, 2, 7, 8, 3, 4, 6, 12)
)
plot_mosaic(df, x = "group", y = "state", weight = "count")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.