R/geom_annotation_func.R

Defines functions geom_annotation_func

Documented in geom_annotation_func

#' geom_annotation
#' 
#' @inheritParams geom_annotation
#' @inheritParams grid::viewport
#' 
#' @param plot.fun function to plot, `p <- plot.fun(data, ...)`
#' @param ... other parameters to `plot.fun`
#' 
#' @example R/examples/ex-geom_anno_func.R
#' @export
geom_annotation_func <- function(
    mapping = NULL, data = NULL,
    plot.fun = NULL, ..., 
    x = 0, y = 0, width = unit(0.5, "npc"), height = unit(0.5, "npc"), just = c(0, 0)
    ) {
  fun <- function(data, coords) {
    p <- plot.fun(data, ...)
    # p <- add_barchart(data$z, brks, cols, fontsize = fontsize, theme = theme, ...)
    
    g <- grid::grobTree(as.grob(p),
      vp = grid::viewport(
        x = x, y = y, just = just,
        width = width, height = height
      )
    )
    g
  }
  grid_panel(fun, mapping, data)
}
rpkgs/gg.layers documentation built on Sept. 14, 2024, 11:07 p.m.