Intro Thoughts

Status Quo

library(tidyverse)
geom_point
## function (mapping = NULL, data = NULL, stat = "identity", position = "identity", 
##     ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) 
## {
##     layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, 
##         position = position, show.legend = show.legend, inherit.aes = inherit.aes, 
##         params = list2(na.rm = na.rm, ...))
## }
## <bytecode: 0x7ff2a53c0f28>
## <environment: namespace:ggplot2>
ggplot(cars) + 
  aes(speed, dist) + 
  layer(stat = StatIdentity, 
        geom = GeomPoint, 
        position = "identity")

StatIdentity
## <ggproto object: Class StatIdentity, Stat, gg>
##     aesthetics: function
##     compute_group: function
##     compute_layer: function
##     compute_panel: function
##     default_aes: uneval
##     dropped_aes: 
##     extra_params: na.rm
##     finish_layer: function
##     non_missing_aes: 
##     optional_aes: 
##     parameters: function
##     required_aes: 
##     retransform: TRUE
##     setup_data: function
##     setup_params: function
##     super:  <ggproto object: Class Stat, gg>
GeomPoint
## <ggproto object: Class GeomPoint, Geom, gg>
##     aesthetics: function
##     default_aes: uneval
##     draw_group: function
##     draw_key: function
##     draw_layer: function
##     draw_panel: function
##     extra_params: na.rm
##     handle_na: function
##     non_missing_aes: size shape colour
##     optional_aes: 
##     parameters: function
##     rename_size: FALSE
##     required_aes: x y
##     setup_data: function
##     setup_params: function
##     use_defaults: function
##     super:  <ggproto object: Class Geom, gg>
GeomPoint2 <- ggproto("GeomPoint2", GeomPoint)


GeomPoint2$required_aes
## [1] "x" "y"
GeomPoint2$required_aes <- c("x", "y")
GeomPoint2$default_aes
## Aesthetic mapping: 
## * `shape`  -> 19
## * `colour` -> "black"
## * `size`   -> 1.5
## * `fill`   -> NA
## * `alpha`  -> NA
## * `stroke` -> 0.5
GeomPoint2$default_aes <- aes(y = NULL)
GeomPoint$draw_group
## <ggproto method>
##   <Wrapper function>
##     function (...) 
## draw_group(..., self = self)
## 
##   <Inner function (f)>
##     function (self, data, panel_params, coord) 
## {
##     cli::cli_abort("{.fn {snake_class(self)}}, has not implemented a {.fn draw_group} method")
## }
GeomPoint$draw_panel
## <ggproto method>
##   <Wrapper function>
##     function (...) 
## draw_panel(..., self = self)
## 
##   <Inner function (f)>
##     function (self, data, panel_params, coord, na.rm = FALSE) 
## {
##     if (is.character(data$shape)) {
##         data$shape <- translate_shape_string(data$shape)
##     }
##     coords <- coord$transform(data, panel_params)
##     stroke_size <- coords$stroke
##     stroke_size[is.na(stroke_size)] <- 0
##     ggname("geom_point", pointsGrob(coords$x, coords$y, pch = coords$shape, 
##         gp = gpar(col = alpha(coords$colour, coords$alpha), fill = fill_alpha(coords$fill, 
##             coords$alpha), fontsize = coords$size * .pt + stroke_size * 
##             .stroke/2, lwd = coords$stroke * .stroke/2)))
## }
GeomPoint$draw_layer
## <ggproto method>
##   <Wrapper function>
##     function (...) 
## draw_layer(..., self = self)
## 
##   <Inner function (f)>
##     function (self, data, params, layout, coord) 
## {
##     if (empty(data)) {
##         n <- if (is.factor(data$PANEL)) 
##             nlevels(data$PANEL)
##         else 1L
##         return(rep(list(zeroGrob()), n))
##     }
##     params <- params[intersect(names(params), self$parameters())]
##     if (nlevels(as.factor(data$PANEL)) > 1L) {
##         data_panels <- split(data, data$PANEL)
##     }
##     else {
##         data_panels <- list(data)
##     }
##     lapply(data_panels, function(data) {
##         if (empty(data)) 
##             return(zeroGrob())
##         panel_params <- layout$panel_params[[data$PANEL[1]]]
##         inject(self$draw_panel(data, panel_params, coord, !!!params))
##     })
## }
ggplot(cars) + 
  aes(speed, dist) + 
  layer(stat = StatIdentity, 
        geom = GeomPoint2, 
        position = "identity")
## Error:
## ! Problem while converting geom to grob.
## ℹ Error occurred in the 1st layer.
## Caused by error in `check.length()`:
## ! 'gpar' element 'fontsize' must not be length 0

Experiment

Closing remarks, Other Relevant Work, Caveats