Skip to content

geom_label + summary: after_stat but before scale #4235

@gregleleu

Description

@gregleleu

I'm using stat summary to compute statistics directly in the graph and show a label for it, for example showing the 90% percentile.
The computed value is passed to the label aesthetic using after_stat and that works fine when there are no axis transformations, but with a log10 transformation the label is in the right place but the text is after the transformation and but before the transformation.
From the documentation I would expect after_stat to be before any scale transformation.

Works fine with regular scale:

library(ggplot2)

ggplot(cars) +
  geom_step(aes(x = speed), stat = "ecdf") +
  geom_label(aes(x = speed, y = 0.9, label = after_stat(x)),
             orientation = "y", stat = "summary", fun = quantile, fun.args = list(probs = 0.9))

image

Wrong text with log10 transformation:

library(ggplot2)

ggplot(cars) +
  geom_step(aes(x = speed), stat = "ecdf") +
  geom_label(aes(x = speed, y = 0.9, label = after_stat(x)),
             orientation = "y", stat = "summary", fun = quantile, fun.args = list(probs = 0.9)) + 
  scale_x_log10()

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions