Permalink
Browse files

Don't use label as a grouping var (fix #465)

  • Loading branch information...
wch committed Apr 4, 2012
1 parent da69b10 commit 0ff654671f3e0b3a68e5a4f3b8a66af5f35ffa07
Showing with 9 additions and 1 deletion.
  1. +2 −1 R/utilities-layer.r
  2. +7 −0 inst/tests/test-aes-grouping.r
View
@@ -2,7 +2,7 @@
#
# If the \code{group} variable is not present, then a new group
# variable is generated from the interaction of all discrete (factor or
-# character) vectors.
+# character) vectors, excluding \code{label}.
#
# @param data.frame
# @value data.frame with group variable
@@ -12,6 +12,7 @@ add_group <- function(data) {
if (is.null(data$group)) {
disc <- vapply(data, is.discrete, logical(1))
+ disc[names(disc) == "label"] <- FALSE
if (any(disc)) {
data$group <- id(data[disc], drop = TRUE)
@@ -22,6 +22,13 @@ test_that("one group per combination of discrete vars", {
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", {
plot <- ggplot(df, aes(x, x, group = x)) + geom_point()

0 comments on commit 0ff6546

Please sign in to comment.