Skip to content

Commit

Permalink
Don't use label as a grouping var (fix #465)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Apr 6, 2012
1 parent da69b10 commit 0ff6546
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/utilities-layer.r
Expand Up @@ -2,7 +2,7 @@
# #
# If the \code{group} variable is not present, then a new group # If the \code{group} variable is not present, then a new group
# variable is generated from the interaction of all discrete (factor or # variable is generated from the interaction of all discrete (factor or
# character) vectors. # character) vectors, excluding \code{label}.
# #
# @param data.frame # @param data.frame
# @value data.frame with group variable # @value data.frame with group variable
Expand All @@ -12,6 +12,7 @@ add_group <- function(data) {


if (is.null(data$group)) { if (is.null(data$group)) {
disc <- vapply(data, is.discrete, logical(1)) disc <- vapply(data, is.discrete, logical(1))
disc[names(disc) == "label"] <- FALSE


if (any(disc)) { if (any(disc)) {
data$group <- id(data[disc], drop = TRUE) data$group <- id(data[disc], drop = TRUE)
Expand Down
7 changes: 7 additions & 0 deletions inst/tests/test-aes-grouping.r
Expand Up @@ -22,6 +22,13 @@ test_that("one group per combination of discrete vars", {
expect_that(groups(plot), equals(4)) expect_that(groups(plot), equals(4))
}) })


test_that("label is not used as a grouping var", {
plot <- ggplot(df, aes(x, x, label = a)) + geom_point()
expect_that(group(plot), equals(c(1, 1, 1, 1)))

plot <- ggplot(df, aes(x, x, colour = a, label = b)) + geom_point()
expect_that(group(plot), equals(c(1, 1, 2, 2)))
})


test_that("group aesthetic overrides defaults", { test_that("group aesthetic overrides defaults", {
plot <- ggplot(df, aes(x, x, group = x)) + geom_point() plot <- ggplot(df, aes(x, x, group = x)) + geom_point()
Expand Down

0 comments on commit 0ff6546

Please sign in to comment.