Skip to content

Fix stat_function() for transformed scales#3908

Merged
clauswilke merged 2 commits intotidyverse:masterfrom
wilkelab:issue-3905-stat-function
Apr 30, 2020
Merged

Fix stat_function() for transformed scales#3908
clauswilke merged 2 commits intotidyverse:masterfrom
wilkelab:issue-3905-stat-function

Conversation

@clauswilke
Copy link
Copy Markdown
Member

Closes #3905.

library(tidyverse)
library(patchwork)

fn <- function(x) {exp(x)}
data <- tibble(x = c(1:10), y = exp(x))

# without data points
p <- ggplot(data, aes(x)) + stat_function(fun = fn)

# with data points
q <- ggplot(data, aes(x, y)) + geom_point() + 
  stat_function(fun = fn)

p / q

(p + scale_y_log10()) / q + scale_y_log10()

(p + scale_y_sqrt()) / q + scale_y_sqrt()

(p + scale_y_reverse()) / q + scale_y_reverse()

(p + scale_x_log10()) / q + scale_x_log10()

(p + scale_x_log10() + scale_y_log10()) /
  q + scale_x_log10() + scale_y_log10()

Created on 2020-03-21 by the reprex package (v0.3.0)

@clauswilke clauswilke requested a review from thomasp85 March 22, 2020 01:42
@clauswilke clauswilke added this to the ggplot2 3.3.1 milestone Mar 22, 2020
@arwarw
Copy link
Copy Markdown

arwarw commented Mar 22, 2020

Wow, that was quick, thanks a lot!

I've tried the patch and I can confirm that this pull request fixes my issue #3905.

Copy link
Copy Markdown
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.

Nice use of after_scale() :-)

@clauswilke
Copy link
Copy Markdown
Member Author

Yes, this literally wouldn't have been possible before 3.3.0.

@clauswilke clauswilke merged commit efd7f0d into tidyverse:master Apr 30, 2020
@clauswilke clauswilke deleted the issue-3905-stat-function branch April 30, 2020 20:41
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.

stat_function disregards log and possibly other scale

3 participants