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

New scale_x_num() and scale_y_num() #404

Merged
merged 15 commits into from
Jan 12, 2022
Merged

New scale_x_num() and scale_y_num() #404

merged 15 commits into from
Jan 12, 2022

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Dec 26, 2021

Do we need to support more scales -- color, fill, size?

Need to document in tibble, implementation remains here.

Closes #400.

library(pillar)

data <- tibble::tibble(
  x = num((1:10) / 100, fixed_exponent = -3, notation = "eng"),
  y = num((1:10) / 100, scale = 100, label = "%"),
  z = 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()

ggplot2::ggplot(data, ggplot2::aes(x, z)) +
  ggplot2::geom_point() +
  scale_y_num(trans = "log10")

Created on 2021-12-26 by the reprex package (v2.0.1)

@krlmlr krlmlr requested a review from hadley December 26, 2021 05:30
@krlmlr krlmlr closed this Dec 28, 2021
@krlmlr krlmlr reopened this Dec 28, 2021
@krlmlr
Copy link
Member Author

krlmlr commented Dec 28, 2021

@lionel- @DavisVaughan @thomasp85: Any idea why this kicks in only after we attach pillar? (Look at the x and y scales.)

CC @Enchufa2.

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()

library(pillar)

ggplot2::ggplot(data, ggplot2::aes(x, y)) +
  ggplot2::geom_point()

Created on 2021-12-28 by the reprex package (v2.0.1)

@krlmlr
Copy link
Member Author

krlmlr commented Dec 28, 2021

Of course this is because how the lookup of the scale functions work. Sorry for the noise. About to file an issue in ggplot2.

@krlmlr krlmlr force-pushed the f-400-ggplot2-num branch from 303a83d to 5b517a3 Compare January 12, 2022 04:39
@krlmlr krlmlr changed the title WIP: New scale_x_num() and scale_y_num() New scale_x_num() and scale_y_num() Jan 12, 2022
@krlmlr krlmlr merged commit 016fe8d into main Jan 12, 2022
@krlmlr krlmlr deleted the f-400-ggplot2-num branch January 12, 2022 09:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make num() work with scales and ggplot2
1 participant