Skip to content

Commit 4cb2af3

Browse files
committed
Output from stats now correctly transformed by scales
1 parent d5b5c6f commit 4cb2af3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ggplot2 0.8 (2008-XX)
22
----------------------------------------
33

4+
* scale_x_log10, scale_y_sqrt etc now correctly transform output from statistics as well as raw data
45
* stat_contour now has arguments to control the position of the contours, rather than relying on the z scale
56
* scale_z_* now removed because no longer used by anything
67
* coord_cartesian now correctly clips instead of dropping points outside of its limits

R/layer.r

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,30 @@ Layer <- proto(expr = {
140140
# of aesthetic mappings occur. This allows the mapping of variables
141141
# created by the statistic, for example, height in a histogram, levels
142142
# on a contour plot.
143+
#
144+
# This also takes care of applying any scale transformations that might
145+
# be necessary
143146
map_statistics <- function(., data, plot) {
144147
gg_apply(data, function(x) .$map_statistic(x, plot=plot))
145148
}
146149

147150
map_statistic <- function(., data, plot) {
148151
if (is.null(data) || length(data) == 0 || nrow(data) == 0) return()
149152
aesthetics <- defaults(.$mapping, defaults(plot$mapping, .$stat$default_aes()))
150-
153+
151154
match <- "\\.\\.([a-zA-z._]+)\\.\\."
152155
new <- aesthetics[grep(match, aesthetics)]
153156
new <- lapply(new, function(x) parse(text = sub(match, "\\1", x))[[1]])
157+
158+
# Add map stat output to aesthetics
159+
stat_data <- as.data.frame(lapply(new, eval, data, baseenv()))
160+
names(stat_data) <- names(new)
154161

155-
for(i in seq_along(new)) {
156-
data[[names(new)[i]]] <- eval(new[[i]], data, baseenv())
157-
}
158-
162+
# Add any new scales, if needed
159163
plot$scales$add_defaults(data, new, plot$plot_env)
164+
stat_data <- plot$scales$transform_df(stat_data)
160165

161-
data
166+
cbind(data, stat_data)
162167
}
163168

164169
reparameterise <- function(., data) {

0 commit comments

Comments
 (0)