diff --git a/NAMESPACE b/NAMESPACE index 892f552f..a4ddbd86 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,9 @@ S3method(autoplot,eof) S3method(cut,eof) S3method(guide_gengrob,colorstrip) +S3method(guide_gengrob,vector) +S3method(guide_geom,colorstrip) +S3method(guide_geom,vector) S3method(guide_train,colorstrip) S3method(guide_train,vector) S3method(interleave,default) @@ -162,6 +165,7 @@ importFrom(data.table,"%chin%") importFrom(ggplot2,.pt) importFrom(ggplot2,autoplot) importFrom(ggplot2,guide_gengrob) +importFrom(ggplot2,guide_geom) importFrom(ggplot2,guide_train) importFrom(ggplot2,scale_type) importFrom(grid,makeContent) diff --git a/R/guide_colorstrip.R b/R/guide_colorstrip.R index d5a9eb15..4b29830f 100644 --- a/R/guide_colorstrip.R +++ b/R/guide_colorstrip.R @@ -171,6 +171,19 @@ guide_train.colorstrip <- function(guide, scale, aesthetic = NULL) { guide } +#' @usage NULL +#' @format NULL +#' @export +#' @rdname guide_colourstrip +#' @keywords internal +#' @importFrom ggplot2 guide_geom +guide_geom.colorstrip <- function(guide, layers, ...) { + if (!inherits(ggplot2::guide_none(), "Guide")) { + return(NextMethod()) + } + bar <- ggplot2::guide_colourbar() + bar$get_layer_key(guide, layers) +} #' @export #' @rdname guide_colourstrip diff --git a/R/guide_vector.R b/R/guide_vector.R index 8d54eadb..be3d931e 100644 --- a/R/guide_vector.R +++ b/R/guide_vector.R @@ -111,6 +111,25 @@ guide_train.vector <- function(guide, scale, aesthetic = NULL) { guide } +#' @export +#' @importFrom ggplot2 guide_geom +guide_geom.vector <- function(guide, layers, ...) { + if (!inherits(ggplot2::guide_none(), "Guide")) { + return(NextMethod()) + } + legend <- ggplot2::guide_legend() + legend$get_layer_key(guide, layers) +} + +#' @export +#' @importFrom ggplot2 guide_gengrob +guide_gengrob.vector <- function(guide, theme) { + if (!inherits(ggplot2::guide_none(), "Guide")) { + return(NextMethod()) + } + legend <- ggplot2::guide_legend() + legend$draw(theme, guide) +} globalVariables(c("C", "R", "key.row", "key.col", "label.row", "label.col"))