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

Add label_log() #312

Merged
merged 9 commits into from
Mar 17, 2022
Merged

Add label_log() #312

merged 9 commits into from
Mar 17, 2022

Conversation

davidchall
Copy link
Contributor

@davidchall davidchall commented Jun 24, 2021

@clauswilke - as discussed in #311. Please let me know what you think.

The default behavior of label_log() is essentially an alias for label_math(expr = 10^.x, format = log10). But it also has a base argument to support other logarithm bases (see examples below).

Since the next release already contains breaking changes, I took the liberty of removing the default expression from label_math(). I don't see any reason for this default expression over any others. But please let me know if this change should be reverted.

library(scales)

demo_log10(c(1, 1e5), labels = label_log())
#> scale_x_log10(labels = label_log())

demo_log10(c(1, 1e5), breaks = breaks_log(base = 2), labels = label_log(base = 2))
#> scale_x_log10(breaks = breaks_log(base = 2), labels = label_log(base = 2))

Created on 2021-06-24 by the reprex package (v2.0.0)

@clauswilke
Copy link
Collaborator

I took the liberty of removing the default expression from label_math()

That's a question for @hadley, but I'd probably keep the current default it since tons of code may depend on it.

@davidchall
Copy link
Contributor Author

I took the liberty of removing the default expression from label_math()

That's a question for @hadley, but I'd probably keep the current default it since tons of code may depend on it.

Ah, I see this function has been around for a long time. Ok - I can reverse that change.

@caparks2
Copy link

caparks2 commented Sep 3, 2021

Can the concept of label_log() be extended to include formatting for other log transformations? It would be particularly helpful if it were to also work with pseudo_log_trans(). Use of label_math(expr = 10^.x, format = log10) plays havoc with the exponent values after using the pseudo log transform in the current stable release of scales.

R/label-log.R Outdated Show resolved Hide resolved
#' @examples
#' demo_log10(c(1, 1e5), labels = label_log())
#' demo_log10(c(1, 1e5), breaks = breaks_log(base = 2), labels = label_log(base = 2))
label_log <- function(base = 10, digits = 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed digits to 3 because I'd prefer not to rely on a global default (and 6 is usually going to be too many)

@hadley hadley merged commit eb3e544 into r-lib:main Mar 17, 2022
@davidchall davidchall deleted the label_log branch March 17, 2022 19:21
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.

4 participants