-
Notifications
You must be signed in to change notification settings - Fork 109
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
trans_format and label_math behaving differently on log10 scale #311
Comments
You want to apply the log10 transformation before the labeler evaluates the expression. This can be achieved using the I do agree this is a confusing pair of default argument values though - I'm not sure if this is the intended behavior? I think it's natural to pair library(scales)
demo_log10(x = c(0.1, 10e07),
breaks = breaks_log(6),
labels = label_math(format = log10))
#> scale_x_log10(breaks = breaks_log(6), labels = label_math(format = log10)) Created on 2021-06-24 by the reprex package (v2.0.0) |
@davidchall Thanks for this example! I had never figured out how to use Also, I'd argue that the log10 case is so common that it would make sense to add a special labeler function for it, something like: label_log10 <- function() label_math(format = log10) |
Yeah, I was totally thinking along the same lines! 😄 |
(Or maybe call it |
Having a dedicated function for library(scales)
demo_log10(c(1, 10), labels = math_format(format = log10))
#> scale_x_log10(labels = math_format(format = log10)) It would be great if the number of digits displayed in the superscript could be controlled in the case above. In addition, a gist linked in this issue has a neat solution for this that might deserve some daylight: source("https://gist.githubusercontent.com/bbolker/5ba6a37d64b06a176e320b2b696b6733/raw/2982cb74d9cb760e6594bed926566c6a3da1b018/scientific_10.R")
demo_log10(c(1, 10), labels = scientific_10)
#> scale_x_log10(labels = scientific_10) Created on 2021-06-24 by the reprex package (v1.0.0) |
@teunbrand Agree with your points. I just wanted to point out that placing the breaks in the mathematically correct location fixes the issue, so maybe break placement for log scales also needs to be revisited. library(scales)
demo_log10(c(1, 10), breaks = c(1, sqrt(10), 10), labels = math_format(format = log10))
#> scale_x_log10(breaks = c(1, sqrt(10), 10), labels = math_format(format = log10)) demo_log10(c(1, 100), breaks = c(1, sqrt(10), 10, 10*sqrt(10), 100), labels = math_format(format = log10))
#> scale_x_log10(breaks = c(1, sqrt(10), 10, 10 * sqrt(10), 100),
#> labels = math_format(format = log10)) Created on 2021-06-24 by the reprex package (v1.0.0) |
author: fontikar
|
You need to copy the code exactly as written. You added quotes that don't belong there. |
Thank you @clauswilke for pointing that out! But like @teunbrand format = log10 is not very pretty for odd number of breaks! The number of breaks is hard for me to determine in a function that takes input of different magnitudes so right now I can't think of a generalisable solution! But I certainly appreciated everyone's help! I'm glad my little problem has sparked this thread and hope to see it evolve into some pretty functions - will stay subscribed! I have implemented bbolker's scientific_10 for now - many thanks @teunbrand for sharing |
author: fontikar
date: 2021-06-15
output: "reprex::reprex_document"
title: drear-kitty_reprex.R
First time issue lodger so forgive me if I am not thorough enough. Feedback welcome!
I've been trying to convert retired scales functions to use the 'new' recommended functions for a particular function in a R package I am developing (https://github.com/traitecoevo/austraits/blob/develop/R/plot_trait_distribution_beeswarm.R).
I noticed label_math() is not behaving the same as trans_format() - code and plots to illustrate below.
Any advice would be greatly appreciated!
Created on 2021-06-15 by the reprex package (v2.0.0)
The text was updated successfully, but these errors were encountered: