Created
July 16, 2019 15:49
-
-
Save paleolimbot/52a0f530b7d73f89b5bd258689408d21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggdebug) # remotes::install_github("paleolimbot/ggdebug") | |
# the classic ggplot! | |
ggplot(mpg) + | |
geom_point(aes(x = displ, y = hwy, colour = class)) | |
# ...is really this: | |
p <- ggplot(mpg) + | |
geom_point( | |
aes(x = displ, y = hwy, colour = class), | |
stat = StatIdentity, | |
position = PositionIdentity | |
) + | |
facet_null() + | |
coord_cartesian() + | |
scale_x_continuous() + | |
scale_y_continuous() + | |
scale_colour_hue() | |
# and is displayed in three steps | |
built <- ggplot_build(p) | |
drawn <- ggplot_gtable(built) | |
grid::grid.draw(drawn) # render | |
# Let's look under the hood! | |
ggdebug( | |
# build | |
FacetNull$compute_layout, FacetNull$map_data, | |
Facet$init_scales, Facet$train_scales, | |
StatIdentity$compute_layer, | |
PositionIdentity$compute_layer, | |
# Facet$init_scales, Facet$train_scales, | |
CoordCartesian$setup_panel_params, | |
# draw | |
# Facet and Layout assemble all the parts | |
CoordCartesian$render_bg, | |
CoordCartesian$render_axis_h, CoordCartesian$render_axis_v, | |
GeomPoint$draw_panel | |
) | |
built <- ggplot_build(p) | |
drawn <- ggplot_gtable(built) | |
grid::grid.draw(drawn) # render | |
ggundebug() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment