plot_stacked_rating
plot_stacked_rating(
data,
feature=None,
level=None,
value='pct',
palette=None,
label_min=1,
show_average=True,
)Stacked rating bars with weighted-average ordering.
Draws a 100%-stacked bar per feature across an ordinal rating scale, labels each segment, and orders features by their weighted mean rating (the leading digit of each level is the weight), so the best-rated feature sits at the top. The weighted mean is appended to each feature label when show_average=True. Feed it a long table with one row per feature and rating level; plot_rating_grid() builds one from a block of columns.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame | Long data with one row per feature and rating level. | required |
| feature | str | Feature column. | None |
| level | str | Rating-level column, e.g. “1 - Very bad” .. “5 - Very good”. The leading digit is used as the numeric weight. | None |
| value | str | Percentage column. Default “pct”. | 'pct' |
| palette | dict | Fill colours keyed by level label. None (default) derives a red, amber, green palette from the level labels themselves. | None |
| label_min | float | Hide segment labels at or below this percentage. Default 1. | 1 |
| show_average | bool | Append the weighted mean to each feature label. Default True. | True |
Returns
| Name | Type | Description |
|---|---|---|
| plotnine.ggplot | The chart. |
See Also
plot_rating_grid, scale_fill_rating
Examples
>>> long = calc_percentage_batch(podracing_survey, starts_with("ratings_"), digits=2)
>>> long["answer"] = recode_likert(long["answer"]).astype(str) + " - " + long["answer"]
>>> plot_stacked_rating(long, "variable", "answer")