Update plot.means_by_group.R to keep order of categories#451
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a double assignment typo and converts the Category column to a factor in plot.means_by_group.R. The reviewer noted that using as.factor() will sort the categories alphabetically, potentially losing their original order. They suggested explicitly setting the factor levels using unique(trimmed$Category) to preserve the original order and drop unused levels.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| x_long <- do.call(rbind, x) | ||
| trimmed <- trimmed <- x_long[x_long$Category != "Total", ] | ||
| trimmed <- x_long[x_long$Category != "Total", ] | ||
| trimmed$Category <- as.factor(trimmed$Category) |
There was a problem hiding this comment.
Using as.factor(trimmed$Category) will coerce the category column to a factor, but by default, R's as.factor() sorts the levels alphabetically. If the categories in the original data are not in alphabetical order, this will lose their original order of appearance, which defeats the main objective of this pull request.\n\nTo preserve the original order of categories as they appear in the data, you should explicitly set the levels using unique(trimmed$Category). This also has the benefit of dropping any unused levels (such as 'Total' if it was already a factor), preventing empty categories from appearing on the plot.
trimmed$Category <- factor(trimmed$Category, levels = unique(trimmed$Category))|
Please see the Gemini suggestion, as |
No description provided.