billboard: Add images to vacant facets in ggplots

Description Usage Arguments Examples

View source: R/billboard.R

Description

When there are more facets than categories of data, fill the vacant facets with images.

Usage

1
billboard(plot, images)

Arguments

plot

A ggplot object

images

A single image grob or a list of image grobs (see examples).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (all(c(require("png"), require("jpeg")))) {
  library(ggplot2)

  img1 <- readPNG(system.file("img", "Rlogo.png", package="ggbillboard"))
  img2 <- readJPEG(system.file("img", "spongebob.png", package="ggbillboard"))
  g1 <- grid::rasterGrob(img1, interpolate=TRUE)
  g2 <- grid::rasterGrob(img2, interpolate=TRUE)

  p1 <-
    ggplot(economics_long, aes(date, value)) +
    geom_line() +
    facet_wrap(vars(variable), scales = "free_y", nrow = 2)

  billboard(p1, g1)
  billboard(p1, list(g1))

  p2 <-
    ggplot(ChickWeight, aes(Time, weight)) +
    geom_point() +
    facet_wrap(~ Diet, ncol = 3)

  billboard(p2, list(g1, g2))
  billboard(p2, list(g2, g1))
}

nacnudus/ggbillboard documentation built on July 9, 2020, 12:50 a.m.