Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for scale_*_reverse() #343

Closed
jkeuskamp opened this issue Feb 24, 2023 · 4 comments
Closed

support for scale_*_reverse() #343

jkeuskamp opened this issue Feb 24, 2023 · 4 comments

Comments

@jkeuskamp
Copy link

jkeuskamp commented Feb 24, 2023

A feature request rather than a bug:
Units facilitates the usage of ggplot with units rather seamlessly.
A small shortcoming is the usage of scale_*_reverse(). This fails with

Error in Ops.units(x, range[1]) : 
  both operands of the expression should be "units" objects

because scale_*_reverse() calls scale_y_continuous(trans = scales::reverse_trans()) to invert the axis.
It would be convenient if scale_*_reverse() would call scale_y_units(trans = scales::reverse_trans()) when applicable.

@Enchufa2
Copy link
Member

Enchufa2 commented Feb 24, 2023

But this works fine:

library(units)

mtcars$consumption <- set_units(mtcars$mpg, mi / gallon)
mtcars$power <- set_units(mtcars$hp, hp)

ggplot(mtcars) +
  geom_point(aes(power, consumption)) +
  scale_x_units(unit = "W", trans="reverse")

So I'm not sure what are you proposing exactly.

@jkeuskamp
Copy link
Author

It does indeed but takes some digging, but it would be more convenient if units would support all ggplot varieties of scale_*_continous. I agree it is not a very pressing issue though 👍

@Enchufa2
Copy link
Member

Enchufa2 commented Feb 24, 2023

So you propose having scale_x_units_reverse, scale_x_units_log10 and so on? Just to clarify, because clearly we cannot make scale_x_reverse call scale_x_units, because scale_x_reverse is, by definition, an alias of scale_x_continuous with that transformation applied.

@jkeuskamp
Copy link
Author

jkeuskamp commented Feb 24, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants