% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_state_frequencies.R
\name{plot_mosaic}
\alias{plot_mosaic}
\title{Draw a Marimekko / Mosaic Plot from a Tidy Data Frame}
\usage{
plot_mosaic(
  data,
  x,
  y,
  weight,
  fill = "y",
  colors = NULL,
  show_labels = TRUE,
  label_size = 3.5,
  x_label = NULL,
  y_label = NULL
)
}
\arguments{
\item{data}{A data.frame in long form. Must contain the columns named
in \code{x}, \code{y}, and \code{weight}.}

\item{x}{Column name for the X (column) variable.}

\item{y}{Column name for the Y (segment) variable.}

\item{weight}{Column name for the cell weight (e.g. count).}

\item{fill}{Either \code{"y"} (color by Y category, e.g. state -- default)
or the name of another column to map to fill (e.g. a residual column
for diverging color).}

\item{colors}{Optional character vector of fill colors. When
\code{fill = "y"}, length must be at least the number of distinct y
levels. Defaults to recycled Okabe-Ito.}

\item{show_labels}{If \code{TRUE}, draw within-segment percentage labels.}

\item{label_size}{Numeric size for segment labels.}

\item{x_label, y_label}{Optional axis labels.}
}
\value{
A \code{ggplot} object.
}
\description{
Low-level rectangle-coordinate builder for marimekko (mosaic) plots.
Column widths are proportional to the per-column total of \code{weight};
within each column, segments stack to height 1 with sub-heights
proportional to each row's share of that column's total.
}
\details{
Used internally by \code{\link{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.
}
\examples{
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")
}
