Skip to content

fix numeric xlevels specification in type_barplot#431

Merged
grantmcdermott merged 5 commits intomainfrom
xlevels-fix
Jun 25, 2025
Merged

fix numeric xlevels specification in type_barplot#431
grantmcdermott merged 5 commits intomainfrom
xlevels-fix

Conversation

@zeileis
Copy link
Copy Markdown
Collaborator

@zeileis zeileis commented Jun 24, 2025

Fixes #430

  • Numeric xlevels specifications in type_barplot() never worked correctly because the x rather than datapoints$x was used in one place. Fixed now.
  • Improved the documentation of xlevels and added two simple examples.
  • Added a warning in cases where xlevels contains entries that do not correspond to any level of x.

@vincentarelbundock
Copy link
Copy Markdown
Collaborator

Thanks for the fix! Maybe insert a test like this:

f = function() {
  tinyplot(
    ~cyl,
    data = mtcars,
    type = "barplot",
    beside = TRUE,
    xlevels = levels(factor(mycars$cyl))[3:1]
  )
}
expect_snapshot_plot(f, label = "barplot_xlevels_issue430")

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Jun 24, 2025

Good suggestion, thanks, added now (but using an example that failed before the fix).

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Jun 24, 2025

Similar improvements have now been done for type_spineplot() as well where xlevels was also added (previously we only had ylevels).

@vincentarelbundock
Copy link
Copy Markdown
Collaborator

I looked at the code and it seems great to me. I think we can merge.

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Jun 24, 2025

Great, thanks for the feedback, this is very helpful. Should we wait for feedback from the original poster?

@vincentarelbundock
Copy link
Copy Markdown
Collaborator

I'm usually too impatient for that, but maybe it's a good idea :)

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Jun 24, 2025

OK, I will let her know when the dev version is on R-universe.

@grantmcdermott grantmcdermott merged commit 3a2e3eb into main Jun 25, 2025
3 checks passed
@grantmcdermott
Copy link
Copy Markdown
Owner

Thanks all, LGTM.

@grantmcdermott grantmcdermott deleted the xlevels-fix branch November 25, 2025 22:19
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.

Unclear error for invalid xlevels param in barplot

3 participants