Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Apply scale transformations in stat_function #730

Closed
wants to merge 1 commit into from

2 participants

@cjp39

stat_function is ignoring scale transformations when passing arguments to its function.

For example,

qplot(1:10, log10(1:10)) + stat_function(fun=function(x) x)
qplot(1:10, log10(1:10)) + stat_function(fun=function(x) x) + scale_x_log10()

In the first plot, the function y=x sits far above the data points. After applying the scale transformation, the function now crosses the data points.

This patch fixes this bug.

@hadley
Owner

Could you please rebase/merge against master, re-document with the development version of roxygen2 (install_github("klutometis/roxygen) and resubmit?

@hadley hadley closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2012
  1. @cjp39
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 1 deletion.
  1. +4 −1 R/stat-function.r
View
5 R/stat-function.r
@@ -54,10 +54,13 @@ StatFunction <- proto(Stat, {
calculate <- function(., data, scales, fun, n=101, args = list(), ...) {
range <- scale_dimension(scales$x, c(0, 0))
xseq <- seq(range[1], range[2], length=n)
+ x_v = if (is.null(scales$x)) xseq else scales$x$trans$inverse(xseq)
+ y_v = do.call(fun, c(list(x_v), args))
+ y = if (is.null(scales$y)) y_v else scales$y$trans$transform(y_v)
data.frame(
x = xseq,
- y = do.call(fun, c(list(xseq), args))
+ y = y
)
}
})
Something went wrong with that request. Please try again.