Skip to content

Commit

Permalink
Test that shrink parameter works
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 19, 2011
1 parent 8a4ef9f commit 3bc0b7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/facet-null.r
Expand Up @@ -6,8 +6,8 @@
#' # don't override it with facet_grid or facet_wrap
#' ggplot(mtcars, aes(mpg, wt)) + geom_point()
#' qplot(mpg, wt, data = mtcars)
facet_null <- function() {
facet(subclass = "null")
facet_null <- function(shrink = TRUE) {
facet(shrink = shrink, subclass = "null")
}

#' @S3method facet_train_layout null
Expand Down
2 changes: 2 additions & 0 deletions R/panel.r
Expand Up @@ -29,6 +29,7 @@ train_layout <- function(panel, facet, data, plot_data) {
panel_info <- facet_train_layout(facet, c(data, list(plot_data)))

panel$panel_info <- panel_info
panel$shrink <- facet$shrink

# Make space for scales
panel$x_scales <- vector("list", max(panel_info$SCALE_X))
Expand Down Expand Up @@ -95,6 +96,7 @@ train_position <- function(panel, data, x_scale, y_scale) {
}

reset_scales <- function(panel) {
if (!panel$shrink) return()
l_ply(panel$x_scales, scale_reset)
l_ply(panel$y_scales, scale_reset)
}
Expand Down
16 changes: 16 additions & 0 deletions inst/tests/test-facet.r
Expand Up @@ -41,3 +41,19 @@ test_that("facets with free scales scale independently", {
expect_that(length(unique(d3$y)), equals(3))
})

test_that("shrink parameter affects scaling", {
l1 <- ggplot(df, aes(1, y)) + geom_point()
r1 <- pranges(l1)

expect_that(r1$x[[1]], equals(c(1, 1)))
expect_that(r1$y[[1]], equals(c(1, 3)))

l2 <- ggplot(df, aes(1, y)) + stat_summary(fun.y = "mean")
r2 <- pranges(l2)
expect_that(r2$y[[1]], equals(c(2, 2)))

l3 <- ggplot(df, aes(1, y)) + stat_summary(fun.y = "mean") +
facet_null(shrink = FALSE)
r3 <- pranges(l3)
expect_that(r3$y[[1]], equals(c(1, 3)))
})

0 comments on commit 3bc0b7e

Please sign in to comment.