Skip to content

Commit f809b7b

Browse files
committed
Grouping tidy up.
Removed order_groups because while it changes the order of the rows, it doesn't affect the order in which the groups are plotted. (Plus it was never well documented)
1 parent eb4e936 commit f809b7b

File tree

9 files changed

+13
-67
lines changed

9 files changed

+13
-67
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Collate:
128128
'grob-absolute.r'
129129
'grob-dotstack.r'
130130
'grob-null.r'
131+
'grouping.r'
131132
'guide-colorbar.r'
132133
'guide-legend.r'
133134
'guides-.r'
@@ -205,7 +206,6 @@ Collate:
205206
'utilities-break.r'
206207
'utilities-grid.r'
207208
'utilities-help.r'
208-
'utilities-layer.r'
209209
'utilities-matrix.r'
210210
'utilities-resolution.r'
211211
'utilities-table.r'

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
ggplot2 1.0.1.9xxx
22
----------------------------------------------------------------
33

4+
* `order` aesthetic is officially no longer supported. It never really worked,
5+
and was poorly documented.
6+
47
* When setting limits with `coord_cartesian()`, it now applies the same
58
expansion factor as setting limits with scales. You can suppress with
69
`expand = FALSE` (#1207).

R/aes-group-order.r

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#' Aesthetics: group, order
1+
#' Aesthetics: group
22
#'
33
#' @name aes_group_order
4-
#' @aliases group order
4+
#' @aliases group
55
#'
66
#' @examples
77
#' \donttest{
@@ -76,15 +76,5 @@
7676
#' # we again need to override the default grouping for that layer with aes(group = Subject)
7777
#' boysbox <- boysbox + geom_boxplot()
7878
#' boysbox + geom_line(aes(group = Subject), colour = "blue")
79-
#'
80-
#' # Use the order aesthetic to change stacking order of bar charts
81-
#' w <- ggplot(diamonds, aes(clarity, fill = cut))
82-
#' w + geom_bar()
83-
#' w + geom_bar(aes(order = desc(cut)))
84-
#'
85-
#' # Can also be used to change plot order of scatter plots
86-
#' d <- ggplot(diamonds, aes(carat, price, colour = cut))
87-
#' d + geom_point()
88-
#' d + geom_point(aes(order = sample(seq_along(carat))))
8979
#' }
9080
NULL

R/aes.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NULL
77
# all <- sort(unique(c(names(.base_to_ggplot), geom_aes, stat_aes)))
88
# dput(all)
99

10-
.all_aesthetics <- c("adj", "alpha", "angle", "bg", "cex", "col", "color", "colour", "fg", "fill", "group", "hjust", "label", "linetype", "lower", "lty", "lwd", "max", "middle", "min", "order", "pch", "radius", "sample", "shape", "size", "srt", "upper", "vjust", "weight", "width", "x", "xend", "xmax", "xmin", "xintercept", "y", "yend", "ymax", "ymin", "yintercept", "z")
10+
.all_aesthetics <- c("adj", "alpha", "angle", "bg", "cex", "col", "color", "colour", "fg", "fill", "group", "hjust", "label", "linetype", "lower", "lty", "lwd", "max", "middle", "min", "pch", "radius", "sample", "shape", "size", "srt", "upper", "vjust", "weight", "width", "x", "xend", "xmax", "xmin", "xintercept", "y", "yend", "ymax", "ymin", "yintercept", "z")
1111

1212
.base_to_ggplot <- c(
1313
"col" = "colour",

R/utilities-layer.r renamed to R/grouping.r

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ NO_GROUP <- -1L
88
# variable is generated from the interaction of all discrete (factor or
99
# character) vectors, excluding \code{label}. The special value \code{NO_GROUP}
1010
# is used for all observations if no discrete variables exist.
11-
#
12-
# @param data.frame
13-
# @value data.frame with group variable
14-
# @keyword internal
15-
# @seealso has_groups
1611
add_group <- function(data) {
1712
if (empty(data)) return(data)
1813

@@ -32,12 +27,6 @@ add_group <- function(data) {
3227
data
3328
}
3429

35-
order_groups <- function(data) {
36-
if (is.null(data$order)) return(data)
37-
38-
data[order(data$order), ]
39-
}
40-
4130
# Is a grouping available?
4231
# (Will return TRUE if an explicit group or a discrete variable with only one
4332
# level existed when add_group() was called.)

R/layer.r

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ Layer <- ggproto("Layer", NULL,
132132
}
133133
check_aesthetics(evaled, n)
134134

135+
# Set special group and panel vars
135136
if (empty(data) && n > 0) {
136137
evaled$PANEL <- 1
137138
} else {
138139
evaled$PANEL <- data$PANEL
139140
}
140-
data.frame(evaled)
141+
evaled <- data.frame(evaled)
142+
evaled <- add_group(evaled)
143+
evaled
141144
},
142145

143146
compute_statistic = function(self, data, panel) {

R/plot-build.r

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ggplot_build <- function(plot) {
4040

4141
# Compute aesthetics to produce data with generalised variable names
4242
data <- by_layer(function(l, d) l$compute_aesthetics(d, plot))
43-
data <- lapply(data, add_group)
4443

4544
# Transform all scales
4645
data <- lapply(data, scales_transform_df, scales = scales)
@@ -56,7 +55,6 @@ ggplot_build <- function(plot) {
5655
# Apply and map statistics
5756
data <- by_layer(function(l, d) l$compute_statistic(d, panel))
5857
data <- by_layer(function(l, d) l$map_statistic(d, plot))
59-
data <- lapply(data, order_groups)
6058

6159
# Make sure missing (but required) aesthetics are added
6260
scales_add_missing(plot, c("x", "y"), plot$plot_env)

man/aes_group_order.Rd

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
\name{aes_group_order}
44
\alias{aes_group_order}
55
\alias{group}
6-
\alias{order}
7-
\title{Aesthetics: group, order}
6+
\title{Aesthetics: group}
87
\description{
9-
Aesthetics: group, order
8+
Aesthetics: group
109
}
1110
\examples{
1211
\donttest{
@@ -81,16 +80,6 @@ boysbox + geom_boxplot()
8180
# we again need to override the default grouping for that layer with aes(group = Subject)
8281
boysbox <- boysbox + geom_boxplot()
8382
boysbox + geom_line(aes(group = Subject), colour = "blue")
84-
85-
# Use the order aesthetic to change stacking order of bar charts
86-
w <- ggplot(diamonds, aes(clarity, fill = cut))
87-
w + geom_bar()
88-
w + geom_bar(aes(order = desc(cut)))
89-
90-
# Can also be used to change plot order of scatter plots
91-
d <- ggplot(diamonds, aes(carat, price, colour = cut))
92-
d + geom_point()
93-
d + geom_point(aes(order = sample(seq_along(carat))))
9483
}
9584
}
9685

tests/testthat/test-aes-grouping.r

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,3 @@ test_that("group param overrides defaults", {
4242
plot <- ggplot(df, aes(a, b)) + geom_point(group = 1)
4343
expect_equal(groups(plot), 1)
4444
})
45-
46-
test_that("order affects plotting order of points", {
47-
base <- ggplot(df, aes(a, x)) + geom_point()
48-
49-
ord1 <- layer_data(base)
50-
ord2 <- layer_data(base + aes(order = x))
51-
rev1 <- layer_data(base + aes(order = -x))
52-
rev2 <- layer_data(base + aes(order = plyr::desc(x)))
53-
54-
expect_equal(ord1$y, 1:4)
55-
expect_equal(ord2$y, 1:4)
56-
expect_equal(rev1$y, 4:1)
57-
expect_equal(rev2$y, 4:1)
58-
})
59-
60-
test_that("order affects plotting order of bars", {
61-
base <- ggplot(df, aes(a, fill = b)) + geom_bar()
62-
63-
ord1 <- layer_data(base)
64-
ord2 <- layer_data(base + aes(order = a))
65-
rev1 <- layer_data(base + aes(order = plyr::desc(b)))
66-
67-
expect_equal(ord1$group, 1:4)
68-
expect_equal(ord2$group, 1:4)
69-
expect_equal(rev1$group, c(2, 1, 4, 3))
70-
})

0 commit comments

Comments
 (0)