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

Transform midpoint argument in relevant scales #5518

Merged
merged 11 commits into from
Dec 14, 2023

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #3198.

Briefly, it uses the scale transformation in mid_rescaler() to transform the midpoint argument. This makes it unnecessary to manually transform that value.

Some examples; standard use of midpoint without a transformation:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

df <- data.frame(x = c(1, 10, 100))

p <- ggplot(df, aes(x, x, colour = x)) +
  geom_point()
p + scale_colour_gradient2(midpoint = 10)

Midpoint is transformed appropriately:

p + scale_colour_gradient2(midpoint = 10, trans = "log10")

Warning when midpoint is invalid:

p + scale_colour_gradient2(midpoint = 0, trans = "log10")
#> Warning in scale_colour_gradient2(midpoint = 0, trans = "log10"): log-10
#> transformation introduced infinite values in `midpoint`.

Created on 2023-11-13 with reprex v2.0.2

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM once updated to new trans name

R/scale-.R Outdated Show resolved Hide resolved
@thomasp85 thomasp85 added this to the ggplot2 3.5.0 milestone Dec 14, 2023
teunbrand and others added 3 commits December 14, 2023 12:50
Merge branch 'main' into midpoint_transform

# Conflicts:
#	R/scale-.R
#	R/scale-gradient.R
#	R/scale-steps.R
#	man/scale_gradient.Rd
#	man/scale_steps.Rd
@teunbrand teunbrand merged commit a417cf4 into tidyverse:main Dec 14, 2023
12 checks passed
@teunbrand teunbrand deleted the midpoint_transform branch December 14, 2023 13:20
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.

midpoint is not transformed in scale_color_gradient2
2 participants