| RMplotTile | R Documentation |
Creates a tile (heat map) plot showing the distribution of responses across all items and response categories. Each cell displays the count (or percentage) of responses, with optional conditional highlighting for cells with low counts. Optional faceting by a grouping variable is provided for inspecting subgroup response distributions before DIF analyses – particularly useful for spotting empty categories or under-represented subgroups before fitting Rasch models per group.
RMplotTile(
data,
group = NULL,
cutoff = 10,
highlight = TRUE,
percent = FALSE,
text_color = "orange",
text_size = 4,
zero_fill = "white",
item_labels = NULL,
category_labels = NULL,
group_labels = NULL,
facet_ncol = NULL,
output = c("ggplot", "dataframe")
)
data |
A data.frame in wide format containing only the item
response columns. Each column is one item, each row is one person.
All columns must be numeric (integer-valued). Response categories
may be coded starting from 0 or 1. Do not include person IDs,
grouping variables, or other non-item columns – supply the grouping
variable separately via |
group |
Optional vector of length |
cutoff |
Integer. Cells with counts below this value are
highlighted (when |
highlight |
Logical. If |
percent |
Logical. If |
text_color |
Character. Colour for non-highlighted cell labels.
Default |
text_size |
Numeric. Size of the cell labels (passed to
|
zero_fill |
Colour for cells with zero responses, or |
item_labels |
Optional character vector of descriptive labels
for the items (y-axis), same length as |
category_labels |
Optional character vector of labels for the
response categories (x-axis), same length as the number of
categories spanning |
group_labels |
Optional character vector of length
|
facet_ncol |
Integer or |
output |
Character. |
Adapted from easyRaschBayes::plot_tile() and extended with the
group parameter for faceted display.
Items are placed on the y-axis (in the same order as the columns of
data, top to bottom) and response categories on the x-axis. Cell
shading represents the count of responses (darker = more responses).
Categories with zero responses are explicitly shown (n = 0), which
helps identify gaps in the response distribution – one of the primary
purposes of the plot, especially before DIF analyses where
under-represented categories within a subgroup can break model
fitting on that subgroup.
When group is supplied, percentages and the highlight cutoff are
applied within each group, so a cell labelled "5" in the group-A
facet contains the count for group A only.
The plot caption reports the sample in the standard
n = X of Y respondents (policy) form: rows with NA group are
dropped (and counted in Y only), while item-level NAs are retained
– each cell simply counts the non-missing responses for that item.
Either a ggplot object or a data.frame, depending on
output.
if (requireNamespace("eRm", quietly = TRUE)) {
data("pcmdat2", package = "eRm")
# Basic tile plot
RMplotTile(pcmdat2)
# With percentages
RMplotTile(pcmdat2, percent = TRUE)
# Faceted by an external grouping variable
set.seed(1)
grp <- sample(c("A", "B"), nrow(pcmdat2), replace = TRUE)
RMplotTile(pcmdat2, group = grp)
# With custom labels and tighter cutoff
RMplotTile(pcmdat2,
group = grp,
group_labels = c("Female", "Male"),
cutoff = 5,
facet_ncol = 2)
# Underlying counts as a data.frame
RMplotTile(pcmdat2, group = grp, output = "dataframe")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.