## ggplot_build() steps revealed --- ``` r library(ggplot2) set.seed(1234) ggplot(palmerpenguins::penguins |> dplyr::sample_n(10), aes(sex)) + stat_count(position = "stack") + facet_wrap(~species) + aes(fill = island) -> p;p ``` ![](debug-ggbuild-slideshow_files/figure-html/unnamed-chunk-1-1.png)<!-- --> --- ```` r # ggplot2::ggplot_build() # function (plot) # { plot <- ggplot2:::plot_clone(p); plot |> str() # step 1.``` ```` ``` ## List of 11 ## $ data : tibble [10 × 8] (S3: tbl_df/tbl/data.frame) ## ..$ species : Factor w/ 3 levels "Adelie","Chinstrap",..: 2 2 1 1 1 1 1 3 1 2 ## ..$ island : Factor w/ 3 levels "Biscoe","Dream",..: 2 2 1 1 2 2 1 1 2 2 ## ..$ bill_length_mm : num [1:10] 51.3 45.6 35 38.1 36.8 40.3 37.7 46.2 38.9 49.8 ## ..$ bill_depth_mm : num [1:10] 18.2 19.4 17.9 16.5 18.5 18.5 16 14.9 18.8 17.3 ## ..$ flipper_length_mm: int [1:10] 197 194 192 198 193 196 183 221 190 198 ## ..$ body_mass_g : int [1:10] 3750 3525 3725 3825 3500 4350 3075 5300 3600 3675 ## ..$ sex : Factor w/ 2 levels "female","male": 2 1 1 1 1 2 1 2 1 1 ## ..$ year : int [1:10] 2007 2009 2009 2009 2009 2008 2009 2008 2008 2009 ## $ layers :List of 1 ## ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' <ggproto object: Class LayerInstance, Layer, gg> ## aes_params: list ## compute_aesthetics: function ## compute_geom_1: function ## compute_geom_2: function ## compute_position: function ## compute_statistic: function ## computed_geom_params: list ## computed_mapping: uneval ## computed_stat_params: list ## constructor: call ## data: waiver ## draw_geom: function ## finish_statistics: function ## geom: <ggproto object: Class GeomBar, GeomRect, Geom, gg> ## aesthetics: function ## default_aes: uneval ## draw_group: function ## draw_key: function ## draw_layer: function ## draw_panel: function ## extra_params: just na.rm orientation ## handle_na: function ## non_missing_aes: xmin xmax ymin ymax ## optional_aes: ## parameters: function ## rename_size: TRUE ## required_aes: x y ## setup_data: function ## setup_params: function ## use_defaults: function ## super: <ggproto object: Class GeomRect, Geom, gg> ## geom_params: list ## inherit.aes: TRUE ## layer_data: function ## map_statistic: function ## mapping: NULL ## position: <ggproto object: Class PositionStack, Position, gg> ## compute_layer: function ## compute_panel: function ## fill: FALSE ## required_aes: ## reverse: FALSE ## setup_data: function ## setup_params: function ## type: NULL ## vjust: 1 ## super: <ggproto object: Class Position, gg> ## print: function ## setup_layer: function ## show.legend: NA ## stat: <ggproto object: Class StatCount, Stat, gg> ## aesthetics: function ## compute_group: function ## compute_layer: function ## compute_panel: function ## default_aes: uneval ## dropped_aes: weight ## extra_params: na.rm orientation ## finish_layer: function ## non_missing_aes: ## optional_aes: ## parameters: function ## required_aes: x|y ## retransform: TRUE ## setup_data: function ## setup_params: function ## super: <ggproto object: Class Stat, gg> ## stat_params: list ## super: <ggproto object: Class Layer, gg> ## $ scales :Classes 'ScalesList', 'ggproto', 'gg' <ggproto object: Class ScalesList, gg> ## add: function ## add_defaults: function ## add_missing: function ## backtransform_df: function ## clone: function ## find: function ## get_scales: function ## has_scale: function ## input: function ## map_df: function ## n: function ## non_position_scales: function ## scales: list ## train_df: function ## transform_df: function ## super: <ggproto object: Class ScalesList, gg> ## $ guides :Classes 'Guides', 'ggproto', 'gg' <ggproto object: Class Guides, gg> ## add: function ## assemble: function ## build: function ## draw: function ## get_custom: function ## get_guide: function ## get_params: function ## get_position: function ## guides: NULL ## merge: function ## missing: <ggproto object: Class GuideNone, Guide, gg> ## add_title: function ## arrange_layout: function ## assemble_drawing: function ## available_aes: any ## build_decor: function ## build_labels: function ## build_ticks: function ## build_title: function ## draw: function ## draw_early_exit: function ## elements: list ## extract_decor: function ## extract_key: function ## extract_params: function ## get_layer_key: function ## hashables: list ## measure_grobs: function ## merge: function ## override_elements: function ## params: list ## process_layers: function ## setup_elements: function ## setup_params: function ## train: function ## transform: function ## super: <ggproto object: Class GuideNone, Guide, gg> ## package_box: function ## print: function ## process_layers: function ## setup: function ## subset_guides: function ## train: function ## update_params: function ## super: <ggproto object: Class Guides, gg> ## $ mapping :List of 2 ## ..$ fill: language ~island ## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> ## ..$ x : language ~sex ## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> ## ..- attr(*, "class")= chr "uneval" ## $ theme : list() ## $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' <ggproto object: Class CoordCartesian, Coord, gg> ## aspect: function ## backtransform_range: function ## clip: on ## default: TRUE ## distance: function ## expand: TRUE ## is_free: function ## is_linear: function ## labels: function ## limits: list ## modify_scales: function ## range: function ## render_axis_h: function ## render_axis_v: function ## render_bg: function ## render_fg: function ## setup_data: function ## setup_layout: function ## setup_panel_guides: function ## setup_panel_params: function ## setup_params: function ## train_panel_guides: function ## transform: function ## super: <ggproto object: Class CoordCartesian, Coord, gg> ## $ facet :Classes 'FacetWrap', 'Facet', 'ggproto', 'gg' <ggproto object: Class FacetWrap, Facet, gg> ## compute_layout: function ## draw_back: function ## draw_front: function ## draw_labels: function ## draw_panels: function ## finish_data: function ## init_scales: function ## map_data: function ## params: list ## setup_data: function ## setup_params: function ## shrink: TRUE ## train_scales: function ## vars: function ## super: <ggproto object: Class FacetWrap, Facet, gg> ## $ plot_env :<environment: R_GlobalEnv> ## $ layout :Classes 'Layout', 'ggproto', 'gg' <ggproto object: Class Layout, gg> ## coord: NULL ## coord_params: list ## facet: NULL ## facet_params: list ## finish_data: function ## get_scales: function ## layout: NULL ## map_position: function ## panel_params: NULL ## panel_scales_x: NULL ## panel_scales_y: NULL ## render: function ## render_labels: function ## reset_scales: function ## resolve_label: function ## setup: function ## setup_panel_guides: function ## setup_panel_params: function ## train_position: function ## super: <ggproto object: Class Layout, gg> ## $ labels :List of 4 ## ..$ fill : chr "island" ## ..$ x : chr "sex" ## ..$ y : chr "count" ## .. ..- attr(*, "fallback")= logi TRUE ## ..$ weight: chr "weight" ## .. ..- attr(*, "fallback")= logi TRUE ## - attr(*, "class")= chr [1:2] "gg" "ggplot" ``` --- ``` r if (length(plot$layers) == 0) { plot <- plot + geom_blank()}; plot |> str() # step 2. ``` ``` ## List of 11 ## $ data : tibble [10 × 8] (S3: tbl_df/tbl/data.frame) ## ..$ species : Factor w/ 3 levels "Adelie","Chinstrap",..: 2 2 1 1 1 1 1 3 1 2 ## ..$ island : Factor w/ 3 levels "Biscoe","Dream",..: 2 2 1 1 2 2 1 1 2 2 ## ..$ bill_length_mm : num [1:10] 51.3 45.6 35 38.1 36.8 40.3 37.7 46.2 38.9 49.8 ## ..$ bill_depth_mm : num [1:10] 18.2 19.4 17.9 16.5 18.5 18.5 16 14.9 18.8 17.3 ## ..$ flipper_length_mm: int [1:10] 197 194 192 198 193 196 183 221 190 198 ## ..$ body_mass_g : int [1:10] 3750 3525 3725 3825 3500 4350 3075 5300 3600 3675 ## ..$ sex : Factor w/ 2 levels "female","male": 2 1 1 1 1 2 1 2 1 1 ## ..$ year : int [1:10] 2007 2009 2009 2009 2009 2008 2009 2008 2008 2009 ## $ layers :List of 1 ## ..$ :Classes 'LayerInstance', 'Layer', 'ggproto', 'gg' <ggproto object: Class LayerInstance, Layer, gg> ## aes_params: list ## compute_aesthetics: function ## compute_geom_1: function ## compute_geom_2: function ## compute_position: function ## compute_statistic: function ## computed_geom_params: list ## computed_mapping: uneval ## computed_stat_params: list ## constructor: call ## data: waiver ## draw_geom: function ## finish_statistics: function ## geom: <ggproto object: Class GeomBar, GeomRect, Geom, gg> ## aesthetics: function ## default_aes: uneval ## draw_group: function ## draw_key: function ## draw_layer: function ## draw_panel: function ## extra_params: just na.rm orientation ## handle_na: function ## non_missing_aes: xmin xmax ymin ymax ## optional_aes: ## parameters: function ## rename_size: TRUE ## required_aes: x y ## setup_data: function ## setup_params: function ## use_defaults: function ## super: <ggproto object: Class GeomRect, Geom, gg> ## geom_params: list ## inherit.aes: TRUE ## layer_data: function ## map_statistic: function ## mapping: NULL ## position: <ggproto object: Class PositionStack, Position, gg> ## compute_layer: function ## compute_panel: function ## fill: FALSE ## required_aes: ## reverse: FALSE ## setup_data: function ## setup_params: function ## type: NULL ## vjust: 1 ## super: <ggproto object: Class Position, gg> ## print: function ## setup_layer: function ## show.legend: NA ## stat: <ggproto object: Class StatCount, Stat, gg> ## aesthetics: function ## compute_group: function ## compute_layer: function ## compute_panel: function ## default_aes: uneval ## dropped_aes: weight ## extra_params: na.rm orientation ## finish_layer: function ## non_missing_aes: ## optional_aes: ## parameters: function ## required_aes: x|y ## retransform: TRUE ## setup_data: function ## setup_params: function ## super: <ggproto object: Class Stat, gg> ## stat_params: list ## super: <ggproto object: Class Layer, gg> ## $ scales :Classes 'ScalesList', 'ggproto', 'gg' <ggproto object: Class ScalesList, gg> ## add: function ## add_defaults: function ## add_missing: function ## backtransform_df: function ## clone: function ## find: function ## get_scales: function ## has_scale: function ## input: function ## map_df: function ## n: function ## non_position_scales: function ## scales: list ## train_df: function ## transform_df: function ## super: <ggproto object: Class ScalesList, gg> ## $ guides :Classes 'Guides', 'ggproto', 'gg' <ggproto object: Class Guides, gg> ## add: function ## assemble: function ## build: function ## draw: function ## get_custom: function ## get_guide: function ## get_params: function ## get_position: function ## guides: NULL ## merge: function ## missing: <ggproto object: Class GuideNone, Guide, gg> ## add_title: function ## arrange_layout: function ## assemble_drawing: function ## available_aes: any ## build_decor: function ## build_labels: function ## build_ticks: function ## build_title: function ## draw: function ## draw_early_exit: function ## elements: list ## extract_decor: function ## extract_key: function ## extract_params: function ## get_layer_key: function ## hashables: list ## measure_grobs: function ## merge: function ## override_elements: function ## params: list ## process_layers: function ## setup_elements: function ## setup_params: function ## train: function ## transform: function ## super: <ggproto object: Class GuideNone, Guide, gg> ## package_box: function ## print: function ## process_layers: function ## setup: function ## subset_guides: function ## train: function ## update_params: function ## super: <ggproto object: Class Guides, gg> ## $ mapping :List of 2 ## ..$ fill: language ~island ## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> ## ..$ x : language ~sex ## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> ## ..- attr(*, "class")= chr "uneval" ## $ theme : list() ## $ coordinates:Classes 'CoordCartesian', 'Coord', 'ggproto', 'gg' <ggproto object: Class CoordCartesian, Coord, gg> ## aspect: function ## backtransform_range: function ## clip: on ## default: TRUE ## distance: function ## expand: TRUE ## is_free: function ## is_linear: function ## labels: function ## limits: list ## modify_scales: function ## range: function ## render_axis_h: function ## render_axis_v: function ## render_bg: function ## render_fg: function ## setup_data: function ## setup_layout: function ## setup_panel_guides: function ## setup_panel_params: function ## setup_params: function ## train_panel_guides: function ## transform: function ## super: <ggproto object: Class CoordCartesian, Coord, gg> ## $ facet :Classes 'FacetWrap', 'Facet', 'ggproto', 'gg' <ggproto object: Class FacetWrap, Facet, gg> ## compute_layout: function ## draw_back: function ## draw_front: function ## draw_labels: function ## draw_panels: function ## finish_data: function ## init_scales: function ## map_data: function ## params: list ## setup_data: function ## setup_params: function ## shrink: TRUE ## train_scales: function ## vars: function ## super: <ggproto object: Class FacetWrap, Facet, gg> ## $ plot_env :<environment: R_GlobalEnv> ## $ layout :Classes 'Layout', 'ggproto', 'gg' <ggproto object: Class Layout, gg> ## coord: NULL ## coord_params: list ## facet: NULL ## facet_params: list ## finish_data: function ## get_scales: function ## layout: NULL ## map_position: function ## panel_params: NULL ## panel_scales_x: NULL ## panel_scales_y: NULL ## render: function ## render_labels: function ## reset_scales: function ## resolve_label: function ## setup: function ## setup_panel_guides: function ## setup_panel_params: function ## train_position: function ## super: <ggproto object: Class Layout, gg> ## $ labels :List of 4 ## ..$ fill : chr "island" ## ..$ x : chr "sex" ## ..$ y : chr "count" ## .. ..- attr(*, "fallback")= logi TRUE ## ..$ weight: chr "weight" ## .. ..- attr(*, "fallback")= logi TRUE ## - attr(*, "class")= chr [1:2] "gg" "ggplot" ``` --- ``` r layers <- plot$layers; layers # step 3. ``` ``` ## [[1]] ## geom_bar: na.rm = FALSE, orientation = NA, width = NULL ## stat_count: na.rm = FALSE, orientation = NA, width = NULL ## position_stack ``` --- ``` r data <- rep(list(NULL), length(layers)); data # step 4. ``` ``` ## [[1]] ## NULL ``` --- ``` r scales <- plot$scales; data # step 1. ``` ``` ## [[1]] ## NULL ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$layer_data(plot$data), layers, data, "computing layer data"); data # step 5. ``` ``` ## [[1]] ## # A tibble: 10 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Chinstrap Dream 51.3 18.2 197 3750 ## 2 Chinstrap Dream 45.6 19.4 194 3525 ## 3 Adelie Biscoe 35 17.9 192 3725 ## 4 Adelie Biscoe 38.1 16.5 198 3825 ## 5 Adelie Dream 36.8 18.5 193 3500 ## 6 Adelie Dream 40.3 18.5 196 4350 ## 7 Adelie Biscoe 37.7 16 183 3075 ## 8 Gentoo Biscoe 46.2 14.9 221 5300 ## 9 Adelie Dream 38.9 18.8 190 3600 ## 10 Chinstrap Dream 49.8 17.3 198 3675 ## # ℹ 2 more variables: sex <fct>, year <int> ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$setup_layer(d, plot), layers, data, "setting up layer"); data # step 6. ``` ``` ## [[1]] ## # A tibble: 10 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Chinstrap Dream 51.3 18.2 197 3750 ## 2 Chinstrap Dream 45.6 19.4 194 3525 ## 3 Adelie Biscoe 35 17.9 192 3725 ## 4 Adelie Biscoe 38.1 16.5 198 3825 ## 5 Adelie Dream 36.8 18.5 193 3500 ## 6 Adelie Dream 40.3 18.5 196 4350 ## 7 Adelie Biscoe 37.7 16 183 3075 ## 8 Gentoo Biscoe 46.2 14.9 221 5300 ## 9 Adelie Dream 38.9 18.8 190 3600 ## 10 Chinstrap Dream 49.8 17.3 198 3675 ## # ℹ 2 more variables: sex <fct>, year <int> ``` --- ``` r layout <- ggplot2:::create_layout(plot$facet, plot$coordinates, plot$layout); data # step 7. ``` ``` ## [[1]] ## # A tibble: 10 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Chinstrap Dream 51.3 18.2 197 3750 ## 2 Chinstrap Dream 45.6 19.4 194 3525 ## 3 Adelie Biscoe 35 17.9 192 3725 ## 4 Adelie Biscoe 38.1 16.5 198 3825 ## 5 Adelie Dream 36.8 18.5 193 3500 ## 6 Adelie Dream 40.3 18.5 196 4350 ## 7 Adelie Biscoe 37.7 16 183 3075 ## 8 Gentoo Biscoe 46.2 14.9 221 5300 ## 9 Adelie Dream 38.9 18.8 190 3600 ## 10 Chinstrap Dream 49.8 17.3 198 3675 ## # ℹ 2 more variables: sex <fct>, year <int> ``` --- ``` r data <- layout$setup(data, plot$data, plot$plot_env); data # step 8. ``` ``` ## [[1]] ## # A tibble: 10 × 9 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Chinstrap Dream 51.3 18.2 197 3750 ## 2 Chinstrap Dream 45.6 19.4 194 3525 ## 3 Adelie Biscoe 35 17.9 192 3725 ## 4 Adelie Biscoe 38.1 16.5 198 3825 ## 5 Adelie Dream 36.8 18.5 193 3500 ## 6 Adelie Dream 40.3 18.5 196 4350 ## 7 Adelie Biscoe 37.7 16 183 3075 ## 8 Gentoo Biscoe 46.2 14.9 221 5300 ## 9 Adelie Dream 38.9 18.8 190 3600 ## 10 Chinstrap Dream 49.8 17.3 198 3675 ## # ℹ 3 more variables: sex <fct>, year <int>, PANEL <fct> ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$compute_aesthetics(d, plot), layers, data, "computing aesthetics"); data # step 9. ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r data <- .ignore_data(data); data # step 10. ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r data <- lapply(data, scales$transform_df); data # step 11 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r scale_x <- function() scales$get_scales("x"); data # step 12 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r scale_y <- function() scales$get_scales("y"); data # step 13 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r layout$train_position(data, scale_x(), scale_y()); data # step 14 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream male 2 4 ## 2 Dream female 2 3 ## 3 Biscoe female 1 1 ## 4 Biscoe female 1 1 ## 5 Dream female 1 3 ## 6 Dream male 1 4 ## 7 Biscoe female 1 1 ## 8 Biscoe male 3 2 ## 9 Dream female 1 3 ## 10 Dream female 2 3 ``` --- ``` r data <- layout$map_position(data); data # step 15 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream 2 2 4 ## 2 Dream 1 2 3 ## 3 Biscoe 1 1 1 ## 4 Biscoe 1 1 1 ## 5 Dream 1 1 3 ## 6 Dream 2 1 4 ## 7 Biscoe 1 1 1 ## 8 Biscoe 2 3 2 ## 9 Dream 1 1 3 ## 10 Dream 1 2 3 ``` --- ``` r data <- .expose_data(data); data # step 16 ``` ``` ## [[1]] ## fill x PANEL group ## 1 Dream 2 2 4 ## 2 Dream 1 2 3 ## 3 Biscoe 1 1 1 ## 4 Biscoe 1 1 1 ## 5 Dream 1 1 3 ## 6 Dream 2 1 4 ## 7 Biscoe 1 1 1 ## 8 Biscoe 2 3 2 ## 9 Dream 1 1 3 ## 10 Dream 1 2 3 ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$compute_statistic(d, layout), layers, data, "computing stat"); data # step 17 ``` ``` ## [[1]] ## count prop x width flipped_aes fill PANEL group ## 1 3 1 1 0.9 FALSE Biscoe 1 1 ## 2 2 1 1 0.9 FALSE Dream 1 3 ## 3 1 1 2 0.9 FALSE Dream 1 4 ## 4 2 1 1 0.9 FALSE Dream 2 3 ## 5 1 1 2 0.9 FALSE Dream 2 4 ## 6 1 1 2 0.9 FALSE Biscoe 3 2 ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$map_statistic(d, plot), layers, data, "mapping stat to aesthetics"); data # step 18 ``` ``` ## [[1]] ## y count prop x width flipped_aes fill PANEL group ## 1 3 3 1 1 0.9 FALSE Biscoe 1 1 ## 2 2 2 1 1 0.9 FALSE Dream 1 3 ## 3 1 1 1 2 0.9 FALSE Dream 1 4 ## 4 2 2 1 1 0.9 FALSE Dream 2 3 ## 5 1 1 1 2 0.9 FALSE Dream 2 4 ## 6 1 1 1 2 0.9 FALSE Biscoe 3 2 ``` --- ``` r plot$scales$add_missing(c("x", "y"), plot$plot_env); data # step 19 ``` ``` ## [[1]] ## y count prop x width flipped_aes fill PANEL group ## 1 3 3 1 1 0.9 FALSE Biscoe 1 1 ## 2 2 2 1 1 0.9 FALSE Dream 1 3 ## 3 1 1 1 2 0.9 FALSE Dream 1 4 ## 4 2 2 1 1 0.9 FALSE Dream 2 3 ## 5 1 1 1 2 0.9 FALSE Dream 2 4 ## 6 1 1 1 2 0.9 FALSE Biscoe 3 2 ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$compute_geom_1(d), layers, data, "setting up geom"); data # step 20 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 3 3 1 1 FALSE Biscoe 1 1 0 3 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$compute_position(d, layout), layers, data, "computing position"); data # step 21 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r data <- .ignore_data(data); data # step 22 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r layout$reset_scales(); data # step 23 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r layout$train_position(data, scale_x(), scale_y()); data #layout # step 24 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r layout$setup_panel_params(); data #layout # step 25 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r data <- layout$map_position(data); data # step 26 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r layout$setup_panel_guides(plot$guides, plot$layers); data #layout # step 27 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r npscales <- scales$non_position_scales(); data #npscales # step 28 ``` ``` ## [[1]] ## y count prop x flipped_aes fill PANEL group ymin ymax xmin xmax ## 1 5 3 1 1 FALSE Biscoe 1 1 2 5 0.55 1.45 ## 2 2 2 1 1 FALSE Dream 1 3 0 2 0.55 1.45 ## 3 1 1 1 2 FALSE Dream 1 4 0 1 1.55 2.45 ## 4 2 2 1 1 FALSE Dream 2 3 0 2 0.55 1.45 ## 5 1 1 1 2 FALSE Dream 2 4 0 1 1.55 2.45 ## 6 1 1 1 2 FALSE Biscoe 3 2 0 1 1.55 2.45 ``` --- ``` r if (npscales$n() > 0) {lapply(data, npscales$train_df); plot$guides <- plot$guides$build(npscales, plot$layers, plot$labels, data); data <- lapply(data, npscales$map_df)}else { plot$guides <- plot$guides$get_custom() }; data# plot$guides step 29 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 ``` --- ``` r data <- .expose_data(data); data # step 30 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$compute_geom_2(d), layers, data, "setting up geom aesthetics"); data # step 31 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ``` --- ``` r data <- ggplot2:::by_layer(function(l, d) l$finish_statistics(d), layers, data, "finishing layer stat"); data # step 32 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ``` --- ``` r data <- layout$finish_data(data); data # step 33 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ``` --- ``` r plot$labels$alt <- get_alt_text(plot); data # step 34 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ``` --- ``` r structure(list(data = data, layout = layout, plot = plot), class = "ggplot_built"); ``` ``` ## $data ## $data[[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ## ## ## $layout ## <ggproto object: Class Layout, gg> ## coord: <ggproto object: Class CoordCartesian, Coord, gg> ## aspect: function ## backtransform_range: function ## clip: on ## default: TRUE ## distance: function ## expand: TRUE ## is_free: function ## is_linear: function ## labels: function ## limits: list ## modify_scales: function ## range: function ## render_axis_h: function ## render_axis_v: function ## render_bg: function ## render_fg: function ## setup_data: function ## setup_layout: function ## setup_panel_guides: function ## setup_panel_params: function ## setup_params: function ## train_panel_guides: function ## transform: function ## super: <ggproto object: Class CoordCartesian, Coord, gg> ## coord_params: list ## facet: <ggproto object: Class FacetWrap, Facet, gg> ## compute_layout: function ## draw_back: function ## draw_front: function ## draw_labels: function ## draw_panels: function ## finish_data: function ## init_scales: function ## map_data: function ## params: list ## setup_data: function ## setup_params: function ## shrink: TRUE ## train_scales: function ## vars: function ## super: <ggproto object: Class FacetWrap, Facet, gg> ## facet_params: list ## finish_data: function ## get_scales: function ## layout: data.frame ## map_position: function ## panel_params: list ## panel_scales_x: list ## panel_scales_y: list ## render: function ## render_labels: function ## reset_scales: function ## resolve_label: function ## setup: function ## setup_panel_guides: function ## setup_panel_params: function ## train_position: function ## super: <ggproto object: Class Layout, gg> ## ## $plot ``` ![](debug-ggbuild-slideshow_files/figure-html/unnamed-chunk-37-1.png)<!-- --> ``` ## ## attr(,"class") ## [1] "ggplot_built" ``` ``` r data # step 35 ``` ``` ## [[1]] ## fill y count prop x flipped_aes PANEL group ymin ymax xmin xmax colour ## 1 #F8766D 5 3 1 1 FALSE 1 1 2 5 0.55 1.45 NA ## 2 #00BFC4 2 2 1 1 FALSE 1 3 0 2 0.55 1.45 NA ## 3 #00BFC4 1 1 1 2 FALSE 1 4 0 1 1.55 2.45 NA ## 4 #00BFC4 2 2 1 1 FALSE 2 3 0 2 0.55 1.45 NA ## 5 #00BFC4 1 1 1 2 FALSE 2 4 0 1 1.55 2.45 NA ## 6 #F8766D 1 1 1 2 FALSE 3 2 0 1 1.55 2.45 NA ## linewidth linetype alpha ## 1 0.5 1 NA ## 2 0.5 1 NA ## 3 0.5 1 NA ## 4 0.5 1 NA ## 5 0.5 1 NA ## 6 0.5 1 NA ``` ## Closing remarks, Other Relevant Work, Caveats