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

Inconsistency geom_abline <-> geom_hline for log10 transformation #3741

Closed
lcougnaud opened this issue Jan 17, 2020 · 3 comments · Fixed by #4434
Closed

Inconsistency geom_abline <-> geom_hline for log10 transformation #3741

lcougnaud opened this issue Jan 17, 2020 · 3 comments · Fixed by #4434
Labels
bug an unexpected problem or unintended behavior scales 🐍
Milestone

Comments

@lcougnaud
Copy link

In case a transformation is applied, the geom_hline function takes the intercept in the initial scale, contrary to the other geoms.

p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() + scale_y_log10()

The line is created if the intercept is specified in the original (non-transformed) scale in geom_hline:

p1 + geom_hline(yintercept = 30)

ggplot_hline_intercept-raw

Contrary to the geom_abline behaviour:

p1 + geom_abline(intercept = log10(30), slope = 0)

ggplot_abline_intercept-log10

@clauswilke
Copy link
Member

I suspect this happens because yintercept is recognized as a position aesthetic and automatically transformed whereas intercept is not. The simple solution would be to rename intercept into yintercept, though I'm not too fond of this approach. In general, I'm not too excited about the current mechanism of identifying position aesthetics, because it seems ad-hoc and error-prone. A better approach would allow geoms and stats to identify which aesthetics should be treated as position aesthetics.

@clauswilke
Copy link
Member

Here is the code that catches all the y position aesthetics. I guess another fix would be to add intercept in line 105.

scale_y_continuous <- function(name = waiver(), breaks = waiver(),
minor_breaks = waiver(), n.breaks = NULL,
labels = waiver(), limits = NULL,
expand = waiver(), oob = censor,
na.value = NA_real_, trans = "identity",
guide = waiver(), position = "left",
sec.axis = waiver()) {
sc <- continuous_scale(
c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final", "lower", "middle", "upper", "y0"),
"position_c", identity, name = name, breaks = breaks, n.breaks = n.breaks,
minor_breaks = minor_breaks, labels = labels, limits = limits,
expand = expand, oob = oob, na.value = na.value, trans = trans,
guide = guide, position = position, super = ScaleContinuousPosition
)

@thomasp85 thomasp85 added bug an unexpected problem or unintended behavior scales 🐍 labels Jan 21, 2020
@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Mar 25, 2021
@thomasp85 thomasp85 reopened this Apr 19, 2021
@thomasp85
Copy link
Member

I agree with @clauswilke that geom_hline()'s behaviour is correct and it is geom_abline() that needs to be corrected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior scales 🐍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants