-
Notifications
You must be signed in to change notification settings - Fork 28
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
integrate ggplot2 scales, closes #164 #294
Conversation
Codecov Report
@@ Coverage Diff @@
## main #294 +/- ##
==========================================
- Coverage 93.15% 92.93% -0.22%
==========================================
Files 18 19 +1
Lines 862 906 +44
==========================================
+ Hits 803 842 +39
- Misses 59 64 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, great work!!
Thanks, @edzer. And @krlmlr thanks for your reference implementation in |
Thanks, good catch: data <- tibble::tibble(
x = pillar::num((1:10) / 100, fixed_exponent = -3, notation = "eng"),
y = pillar::num((1:10) / 100, scale = 100, label = "%"),
z = pillar::num(10^(-5:4), notation = "si")
)
data
#> # A tibble: 10 × 3
#> x y z
#> <eng> % <si>
#> 1 10e-3 1 10µ
#> 2 20e-3 2 100µ
#> 3 30e-3 3 1m
#> 4 40e-3 4 10m
#> 5 50e-3 5 100m
#> 6 60e-3 6 1
#> 7 70e-3 7 10
#> 8 80e-3 8 100
#> 9 90e-3 9 1k
#> 10 100e-3 10 10k
ggplot2::ggplot(data, ggplot2::aes(x, y)) +
ggplot2::geom_point() Created on 2021-12-28 by the reprex package (v2.0.1) I'll try to fix in pillar. |
This is a current limitation, about to file a ggplot2 issue. For now, should |
Great, thanks.
That's a very good idea. |
9ec86ee will do for now. In our case, I used library(ggplot2)
mtcars$consumption <- units::set_units(mtcars$mpg, mi / gallon)
mtcars$power <- units::set_units(mtcars$hp, hp)
ggplot(mtcars) +
geom_point(aes(power, consumption))
#> Error in scale_type.units(x): Variable of class 'units' found, but 'units' package is not attached.
#> Please, attach it using 'library(units)' to properly show scales with units.
ggplot(mtcars) +
geom_point(aes(power, consumption)) +
units::scale_x_units(unit = "W") +
units::scale_y_units(unit = "km/l") library(units)
#> udunits database from /usr/share/udunits/udunits2.xml
ggplot(mtcars) +
geom_point(aes(power, consumption)) Created on 2021-12-28 by the reprex package (v2.0.1) |
@edzer I've adapted the code from
ggforce
and added Thomas as a contributor in the DESCRIPTION. I've called the functionsscale_*_units
instead ofscale_*_unit
to follow the naming conventions. I've also droppedggforce
from the DESCRIPTION, demos and vignettes, but preserving the mention in the ACKs (i.e., this). Is that ok?