diff --git a/DESCRIPTION b/DESCRIPTION index c2b96ec3a6..ca0464ce44 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,8 @@ Imports: digest, grid, reshape2, - scales + scales, + memoise Suggests: quantreg, Hmisc, diff --git a/NAMESPACE b/NAMESPACE index fd03fef87a..3777278589 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -187,6 +187,7 @@ export(ylab) export(ylim) import(digest) import(grid) +import(memoise) import(plyr) import(reshape2) import(scales) diff --git a/R/coord-cartesian-.r b/R/coord-cartesian-.r index 41ef54937c..92631fb027 100644 --- a/R/coord-cartesian-.r +++ b/R/coord-cartesian-.r @@ -63,42 +63,30 @@ coord_transform.cartesian <- function(., data, details) { #' @S3method coord_train cartesian coord_train.cartesian <- function(coord, scales) { - if (is.null(coord$limits$x)) { - x.range <- scale_dimension(scales$x) - } else { - x.range <- range(scale_transform(scales$x, coord$limits[["x"]])) - if (coord$wise) { - scales$x$limits <- x.range - x.range <- expand_range(x.range, - scales$x$expand[1], scales$x$expand[2]) - } - } - - x.major <- rescale(scale_break_positions(scales$x), from = x.range) - x.minor <- rescale(scale_breaks_minor(scales$x), from = x.range) - x.labels <- scale_labels(scales$x) + c(train_cartesian(scales$x, coord$limits$x, "x"), + train_cartesian(scales$y, coord$limits$y, "y")) +} - if (is.null(coord$limits$y)) { - y.range <- scale_dimension(scales$y) +train_cartesian <- memoise(function(scale, limits, name) { + if (is.null(limits)) { + range <- scale_dimension(scale) } else { - y.range <- range(scale_transform(scales$y, coord$limits$y)) - + range <- range(scale_transform(scale, limits)) if (coord$wise) { - scales$y$limits <- y.range - y.range <- expand_range(y.range, - scales$y$expand[1], scales$y$expand[2]) + scale$limits <- x.range + range <- expand_range(range, scale$expand[1], scale$expand[2]) } } - y.major <- rescale(scale_break_positions(scales$y), from = y.range) - y.minor <- rescale(scale_breaks_minor(scales$y), from = y.range) - y.labels <- scale_labels(scales$y) - list( - x.range = x.range, y.range = y.range, - x.major = x.major, x.minor = x.minor, x.labels = x.labels, - y.major = y.major, y.minor = y.minor, y.labels = y.labels - ) -} + major <- rescale(scale_break_positions(scale), from = range) + minor <- rescale(scale_breaks_minor(scale), from = range) + labels <- scale_labels(scale) + + out <- list(range = range, major = major, minor = minor, labels = labels) + names(out) <- paste(name, names(out), sep = ".") + out +}) + icon.cartesian <- function(.) { gTree(children = gList( diff --git a/R/ggplot2.r b/R/ggplot2.r index d2787dd7ab..ab6dd546dc 100644 --- a/R/ggplot2.r +++ b/R/ggplot2.r @@ -3,7 +3,7 @@ #' @name ggplot2 #' @docType package #' @aliases ggplot2 package-ggplot2 -#' @import plyr digest scales grid reshape2 +#' @import plyr digest scales grid reshape2 memoise NULL #' Prices of 50,000 round cut diamonds diff --git a/R/guides-axis.r b/R/guides-axis.r index b0d93abf24..431f05ce6a 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -87,4 +87,4 @@ guide_axis <- function(at, labels, position="right", theme) { width = grobWidth(fg), height = grobHeight(fg) ) -} +} \ No newline at end of file