Intro Thoughts

Status Quo

library(tidyverse)

Experiment

GeomBarbell <- ggproto("GeomBarbell", Geom,
  
  required_aes = c("x", "y", "xend", "yend"),
  
  default_aes = aes(
    colour = "black",
    linewidth = .5,
    size = 2,
    linetype = 1,
    shape = 19,
    fill = NA,
    alpha = NA,
    stroke = 1
  ),
  
  draw_panel = function(data, panel_params, coord, ...) {
    
    # Transformed data for the points
    point1 <- transform(data) 
    point2 <- transform(data, x = xend, y = yend)    
    
    # Return all three components
    grid::gList(
      GeomSegment$draw_panel(data, panel_params, coord, ...),
      GeomPoint$draw_panel(point1, panel_params, coord, ...),
      GeomPoint$draw_panel(point2, panel_params, coord, ...)
    )
  }
) 

ggplot(cars) + 
  aes(speed, dist, xend = speed + 2, yend = dist) +
  stat_identity(geom = GeomBarbell)

combine_geoms <- function(geom1 = GeomPoint, geom2 = GeomText){
  
GeomCombo2 <-   ggproto("GeomCombo2", Geom,
          # required_aes = unique(c(geom1$required_aes, geom2$required_aes)),
          default_aes = modifyList(geom1$default_aes, geom2$default_aes),
  draw_panel = function(data, panel_params, coord, ...) {
    
    # Return all three components
    grid::gList(
      geom1$draw_panel(data, panel_params, coord, ...),
      geom2$draw_panel(data, panel_params, coord, ...)
    )
  }
         )
   
GeomCombo2

 }
   


   

library(ggplot2)
ggplot(cars) + 
  aes(speed, dist, label = speed) + 
  stat_identity(geom = combine_geoms(), alpha = .5)

library(ggplot2)
ggplot(cars) + 
  aes(speed, dist, label = speed) + 
  stat_identity(geom = combine_geoms(GeomPoint, GeomLabel), 
                alpha = .5,
                hjust = 1)

ggplot(cars) + 
  aes(speed, dist, label = speed) + 
  stat_identity(geom = combine_geoms(GeomPoint, GeomTile), 
                alpha = .5,
                hjust = 1)
## Warning in stat_identity(geom = combine_geoms(GeomPoint, GeomTile), alpha =
## 0.5, : Ignoring unknown parameters: `hjust`
## Error in `stat_identity()`:
## ! Problem while converting geom to grob.
## ℹ Error occurred in the 1st layer.
## Caused by error in `unit()`:
## ! 'x' and 'units' must have length > 0

Closing remarks, Other Relevant Work, Caveats