@@ -140,25 +140,30 @@ Layer <- proto(expr = {
140
140
# of aesthetic mappings occur. This allows the mapping of variables
141
141
# created by the statistic, for example, height in a histogram, levels
142
142
# on a contour plot.
143
+ #
144
+ # This also takes care of applying any scale transformations that might
145
+ # be necessary
143
146
map_statistics <- function (. , data , plot ) {
144
147
gg_apply(data , function (x ) . $ map_statistic(x , plot = plot ))
145
148
}
146
149
147
150
map_statistic <- function (. , data , plot ) {
148
151
if (is.null(data ) || length(data ) == 0 || nrow(data ) == 0 ) return ()
149
152
aesthetics <- defaults(. $ mapping , defaults(plot $ mapping , . $ stat $ default_aes()))
150
-
153
+
151
154
match <- " \\ .\\ .([a-zA-z._]+)\\ .\\ ."
152
155
new <- aesthetics [grep(match , aesthetics )]
153
156
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 )
154
161
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
159
163
plot $ scales $ add_defaults(data , new , plot $ plot_env )
164
+ stat_data <- plot $ scales $ transform_df(stat_data )
160
165
161
- data
166
+ cbind( data , stat_data )
162
167
}
163
168
164
169
reparameterise <- function (. , data ) {
0 commit comments