Intro Thoughts

Status Quo

library(tidyverse)

Experiment

library(tidyverse)
theme_set(theme_bw())

compute_layer_applique <- function(data, params, panel, ncol = 3, x0 = .05, y0 = .75, x_scale = .2, y_scale = .2) {
    
    range_x <- (max(data$x)-min(data$x))
    range_y <- (max(data$y)-min(data$y))
    if(range_x == 0){range_x <- 1}
    if(range_y == 0){range_y <- 1}
    
    ggplot2::transform_position(
      df = data,
      trans_x = function(x) {I(x_scale * x/(range_x) + x0)}, 
      trans_y = function(y) {I(y_scale * y/(range_y) + y0)}
    )
  }

PositionApplique <- ggproto(`_class` = 'PositionApplique', 
                        `_inherit` = Position,
                        required_aes = c('x', 'y'),
                        compute_layer = compute_layer_applique)


position_applique <- function() {
  ggproto(NULL, PositionApplique)
}

library(statexpress)

ggplot(cars) + 
  aes(x = speed) + 
  geom_histogram() + 
  geom_histogram(position = "applique", 
                 fill = "darkred")
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

ggplot(cars) + 
  aes(speed) + 
  geom_point(aes(y = dist)) + 
  geom_histogram(position = "applique", 
                 fill = "darkred")
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

Closing remarks, Other Relevant Work, Caveats