Skip to content

Commit

Permalink
Add grouping data
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 19, 2011
1 parent 702e341 commit 8a4ef9f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions R/plot-build.r
Expand Up @@ -24,6 +24,7 @@ ggplot_build <- function(plot) {

# Compute aesthetics to produce data with generalised variable names
data <- dlapply(function(d, p) p$compute_aesthetics(d, plot))
data <- lapply(data, add_group)

# Transform all scales
data <- lapply(data, scales_transform_df, scales = scales)
Expand Down
14 changes: 14 additions & 0 deletions inst/tests/helper-plot-data.r
Expand Up @@ -12,3 +12,17 @@ cdata <- function(plot) {
})
})
}

pranges <- function(plot) {
panels <- ggplot_build(plot)$panels

x_ranges <- lapply(panels$x_scales, scale_limits)
y_ranges <- lapply(panels$y_scales, scale_limits)


npscales <- plot$scales$non_position_scales()
npranges <- lapply(npscales$scales$scales, scale_limits)


c(list(x = x_ranges, y = y_ranges), npranges)
}
4 changes: 2 additions & 2 deletions inst/tests/test-build.r
Expand Up @@ -32,8 +32,8 @@ test_that("non-position aesthetics are mapped", {
geom_point()
d1 <- pdata(l1)[[1]]

expect_that(sort(names(d1)),
equals(sort(c("x", "y", "fill", "colour", "shape", "size", "PANEL"))))
expect_that(sort(names(d1)), equals(sort(c("x", "y", "fill", "group",
"colour", "shape", "size", "PANEL"))))

l2 <- l1 + scale_colour_manual(values = c("blue", "red", "yellow"))
d2 <- pdata(l2)[[1]]
Expand Down
2 changes: 1 addition & 1 deletion inst/tests/test-facet.r
Expand Up @@ -15,7 +15,7 @@ test_that("facets split up the data", {
d3 <- pdata(l3)[[1]]

expect_that(d2, equals(d3))
expect_that(sort(names(d2)), equals(sort(c("x", "y", "PANEL"))))
expect_that(sort(names(d2)), equals(sort(c("x", "y", "group", "PANEL"))))
expect_that(d2$PANEL, equals(factor(1:3)))
})

Expand Down

0 comments on commit 8a4ef9f

Please sign in to comment.