Today in attempting to understand design principles:
In A Layered Grammar of Graphics we learn that a layer consists of 5 things:
Layer:
- Data
- Mapping
- Geom
- Stat
- Position
When we create a ggproto
object and print it, we are informed of 4/5 of the components of the layer: mapping, geom, stat, and position. When the data is also provided it would seem logical that the 5th component should be printed in the resultant object as well.
For example
geom_point(aes(Sepal.Length, Sepal.Width), data = iris)
#> mapping: x = ~Sepal.Length, y = ~Sepal.Width
#> geom_point: na.rm = FALSE
#> stat_identity: na.rm = FALSE
#> position_identity
Created on 2020-03-03 by the reprex package (v0.3.0)
When data is provided to the object, they behave differently.
library(ggplot2)
# define point layers
w_data <- geom_point(aes(Sepal.Length, Sepal.Width), iris)
wo_data <- geom_point(aes(Sepal.Length, Sepal.Width))
#
ggplot() +
w_data
ggplot() +
wo_data
#> Error in FUN(X[[i]], ...): object 'Sepal.Length' not found
Created on 2020-03-03 by the reprex package (v0.3.0)
My thinking is that when the data are or are not provided, that should be explicitly stated in the print method as it has very real consequences in the way that one can use the resultant object.