@@ -39,28 +39,28 @@ ggplot_build.ggplot_built <- function(plot) {
39
39
# ' @export
40
40
ggplot_build.ggplot <- function (plot ) {
41
41
plot <- plot_clone(plot )
42
- if (length(plot $ layers ) == 0 ) {
42
+ if (length(plot @ layers ) == 0 ) {
43
43
plot <- plot + geom_blank()
44
44
}
45
45
46
- layers <- plot $ layers
46
+ layers <- plot @ layers
47
47
data <- rep(list (NULL ), length(layers ))
48
48
49
- scales <- plot $ scales
49
+ scales <- plot @ scales
50
50
51
51
# Allow all layers to make any final adjustments based
52
52
# on raw input data and plot info
53
- data <- by_layer(function (l , d ) l $ layer_data(plot $ data ), layers , data , " computing layer data" )
53
+ data <- by_layer(function (l , d ) l $ layer_data(plot @ data ), layers , data , " computing layer data" )
54
54
data <- by_layer(function (l , d ) l $ setup_layer(d , plot ), layers , data , " setting up layer" )
55
55
56
56
# Initialise panels, add extra data for margins & missing faceting
57
57
# variables, and add on a PANEL variable to data
58
- layout <- create_layout(plot $ facet , plot $ coordinates , plot $ layout )
59
- data <- layout $ setup(data , plot $ data , plot $ plot_env )
58
+ layout <- create_layout(plot @ facet , plot @ coordinates , plot @ layout )
59
+ data <- layout $ setup(data , plot @ data , plot @ plot_env )
60
60
61
61
# Compute aesthetics to produce data with generalised variable names
62
62
data <- by_layer(function (l , d ) l $ compute_aesthetics(d , plot ), layers , data , " computing aesthetics" )
63
- plot $ labels <- setup_plot_labels(plot , layers , data )
63
+ plot @ labels <- setup_plot_labels(plot , layers , data )
64
64
data <- .ignore_data(data )
65
65
66
66
# Transform all scales
@@ -80,7 +80,7 @@ ggplot_build.ggplot <- function(plot) {
80
80
data <- by_layer(function (l , d ) l $ map_statistic(d , plot ), layers , data , " mapping stat to aesthetics" )
81
81
82
82
# Make sure missing (but required) aesthetics are added
83
- plot $ scales $ add_missing(c(" x" , " y" ), plot $ plot_env )
83
+ plot @ scales $ add_missing(c(" x" , " y" ), plot @ plot_env )
84
84
85
85
# Reparameterise geoms from (e.g.) y and width to ymin and ymax
86
86
data <- by_layer(function (l , d ) l $ compute_geom_1(d ), layers , data , " setting up geom" )
@@ -98,27 +98,27 @@ ggplot_build.ggplot <- function(plot) {
98
98
data <- layout $ map_position(data )
99
99
100
100
# Hand off position guides to layout
101
- layout $ setup_panel_guides(plot $ guides , plot $ layers )
101
+ layout $ setup_panel_guides(plot @ guides , plot @ layers )
102
102
103
103
# Complete the plot's theme
104
- plot $ theme <- plot_theme(plot )
104
+ plot @ theme <- plot_theme(plot )
105
105
106
106
# Train and map non-position scales and guides
107
107
npscales <- scales $ non_position_scales()
108
108
if (npscales $ n() > 0 ) {
109
- npscales $ set_palettes(plot $ theme )
109
+ npscales $ set_palettes(plot @ theme )
110
110
lapply(data , npscales $ train_df )
111
- plot $ guides <- plot $ guides $ build(npscales , plot $ layers , plot $ labels , data , plot $ theme )
111
+ plot @ guides <- plot @ guides $ build(npscales , plot @ layers , plot @ labels , data , plot @ theme )
112
112
data <- lapply(data , npscales $ map_df )
113
113
} else {
114
114
# Only keep custom guides if there are no non-position scales
115
- plot $ guides <- plot $ guides $ get_custom()
115
+ plot @ guides <- plot @ guides $ get_custom()
116
116
}
117
117
data <- .expose_data(data )
118
118
119
119
# Fill in defaults etc.
120
120
data <- by_layer(
121
- function (l , d ) l $ compute_geom_2(d , theme = plot $ theme ),
121
+ function (l , d ) l $ compute_geom_2(d , theme = plot @ theme ),
122
122
layers , data , " setting up geom aesthetics"
123
123
)
124
124
@@ -129,7 +129,7 @@ ggplot_build.ggplot <- function(plot) {
129
129
data <- layout $ finish_data(data )
130
130
131
131
# Consolidate alt-text
132
- plot $ labels $ alt <- get_alt_text(plot )
132
+ plot @ labels $ alt <- get_alt_text(plot )
133
133
134
134
structure(
135
135
list (data = data , layout = layout , plot = plot ),
@@ -169,7 +169,7 @@ layer_scales <- get_panel_scales
169
169
get_layer_grob <- function (plot = get_last_plot(), i = 1L ) {
170
170
b <- ggplot_build(plot )
171
171
172
- b $ plot $ layers [[i ]]$ draw_geom(b $ data [[i ]], b $ layout )
172
+ b $ plot @ layers [[i ]]$ draw_geom(b $ data [[i ]], b $ layout )
173
173
}
174
174
175
175
# ' @export
@@ -196,7 +196,7 @@ layer_grob <- get_layer_grob
196
196
# ' @export
197
197
ggplot_gtable <- function (data ) {
198
198
# Attaching the plot env to be fetched by deprecations etc.
199
- attach_plot_env(data $ plot $ plot_env )
199
+ attach_plot_env(data $ plot @ plot_env )
200
200
201
201
UseMethod(' ggplot_gtable' )
202
202
}
@@ -206,33 +206,33 @@ ggplot_gtable.ggplot_built <- function(data) {
206
206
plot <- data $ plot
207
207
layout <- data $ layout
208
208
data <- data $ data
209
- theme <- plot $ theme
209
+ theme <- plot @ theme
210
210
211
- geom_grobs <- by_layer(function (l , d ) l $ draw_geom(d , layout ), plot $ layers , data , " converting geom to grob" )
211
+ geom_grobs <- by_layer(function (l , d ) l $ draw_geom(d , layout ), plot @ layers , data , " converting geom to grob" )
212
212
213
- plot_table <- layout $ render(geom_grobs , data , theme , plot $ labels )
213
+ plot_table <- layout $ render(geom_grobs , data , theme , plot @ labels )
214
214
215
215
# Legends
216
- legend_box <- plot $ guides $ assemble(theme )
216
+ legend_box <- plot @ guides $ assemble(theme )
217
217
plot_table <- table_add_legends(plot_table , legend_box , theme )
218
218
219
219
# Title
220
220
title <- element_render(
221
- theme , " plot.title" , plot $ labels $ title ,
221
+ theme , " plot.title" , plot @ labels $ title ,
222
222
margin_y = TRUE , margin_x = TRUE
223
223
)
224
224
title_height <- grobHeight(title )
225
225
226
226
# Subtitle
227
227
subtitle <- element_render(
228
- theme , " plot.subtitle" , plot $ labels $ subtitle ,
228
+ theme , " plot.subtitle" , plot @ labels $ subtitle ,
229
229
margin_y = TRUE , margin_x = TRUE
230
230
)
231
231
subtitle_height <- grobHeight(subtitle )
232
232
233
233
# whole plot annotation
234
234
caption <- element_render(
235
- theme , " plot.caption" , plot $ labels $ caption ,
235
+ theme , " plot.caption" , plot @ labels $ caption ,
236
236
margin_y = TRUE , margin_x = TRUE
237
237
)
238
238
caption_height <- grobHeight(caption )
@@ -283,7 +283,7 @@ ggplot_gtable.ggplot_built <- function(data) {
283
283
plot_table <- gtable_add_grob(plot_table , caption , name = " caption" ,
284
284
t = - 1 , b = - 1 , l = caption_l , r = caption_r , clip = " off" )
285
285
286
- plot_table <- table_add_tag(plot_table , plot $ labels $ tag , theme )
286
+ plot_table <- table_add_tag(plot_table , plot @ labels $ tag , theme )
287
287
288
288
# Margins
289
289
plot_margin <- calc_element(" plot.margin" , theme ) %|| % margin()
@@ -298,7 +298,7 @@ ggplot_gtable.ggplot_built <- function(data) {
298
298
}
299
299
300
300
# add alt-text as attribute
301
- attr(plot_table , " alt-label" ) <- plot $ labels $ alt
301
+ attr(plot_table , " alt-label" ) <- plot @ labels $ alt
302
302
303
303
plot_table
304
304
}
0 commit comments