Skip to content

Conversation

Copy link

Copilot AI commented Aug 11, 2025

Fixes a bug in create.barplot() where sample.order = 'increasing'/'decreasing' was incorrectly ordering stacked grouped barplots by the first group's values only, instead of ordering by the total stacked height/width across all groups.

Problem

When creating stacked barplots with groups and using sample.order = 'increasing' or 'decreasing', the bars were ordered based only on the first group's values rather than the sum of all groups for each sample. This resulted in visually incorrect ordering that didn't match user expectations.

For example, with this data:

  • Sample A: G1=1, G2=9, G3=0 → total=10 (first value: 1)
  • Sample B: G1=5, G2=2, G3=1 → total=8 (first value: 5)
  • Sample C: G1=2, G2=1, G3=1 → total=4 (first value: 2)
  • Sample D: G1=3, G2=2, G3=1 → total=6 (first value: 3)

The old logic would order by first values: A(1), C(2), D(3), B(5)
The correct logic should order by totals: C(4), D(6), B(8), A(10)

Solution

Modified the sample ordering logic in create.barplot.R to:

  1. Detect stacked grouped barplots: Check if stack = TRUE AND groups is not NULL
  2. Compute per-sample totals: Sum values across all groups for each sample using na.rm = TRUE
  3. Order by totals: Use these computed totals instead of first group values only
  4. Preserve existing behavior: Non-stacked plots or plots without groups continue to work as before

The fix handles both vertical orientation (y-values) and horizontal orientation (x-values).

Changes

  • R/create.barplot.R: Added conditional logic to compute sample totals for stacked grouped barplots
  • tests/testthat/test-stacked-sample-order.R: Added comprehensive tests to verify correct ordering
  • NEWS.md: Documented the bug fix

Testing

Added tests that verify:

  • sample.order = 'increasing' produces ascending totals left-to-right
  • sample.order = 'decreasing' produces descending totals left-to-right
  • Both vertical and horizontal orientations work correctly
  • Non-stacked and non-grouped plots maintain existing behavior

Fixes #48

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /usr/lib/R/bin/exec/R -e install.packages(c('devtools',~+~'testthat'),~+~repos='REDACTED') (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…al stacked height/width

Co-authored-by: tnyamaguchi <62572751+tnyamaguchi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sample.order for stacked barplots to sort by total stacked height Fix sample.order handling for stacked grouped barplots - order by total stacked height/width Aug 11, 2025
Copilot AI requested a review from tnyamaguchi August 11, 2025 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create barplot "sample.order" option doesn't work properly when stack = TRUE

2 participants