R/ggbackground.R

Defines functions ggbackground

Documented in ggbackground

##' set background for ggplot
##'
##'
##' @title ggbackground
##' @param gg gg object
##' @param background background image
##' @param ... additional parameter to manipulate background image, see also geom_image
##' @return gg object
##' @importFrom ggplot2 ggplot
##' @export
##' @author guangchuang yu
ggbackground <- function(gg, background, ...) {
    ggplot(data.frame(x = 0:1, y = 0:1), aes_(x = ~x, y = ~y)) +
        geom_image(image = background,size=Inf, ...) +
        geom_subview(subview = gg + theme_transparent(),
                     width=Inf, height=Inf, x=.5, y=.5) +
        theme_nothing()
}

Try the ggimage package in your browser

Any scripts or data that you put into this service are public.

ggimage documentation built on July 9, 2023, 6:24 p.m.