Learn R Programming

ggimage (version 0.3.6)

geom_image: geom_image

Description

geom layer for visualizing image files

Usage

geom_image(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  inherit.aes = TRUE,
  na.rm = FALSE,
  by = "width",
  nudge_x = 0,
  nudge_y = 0,
  use_cache = TRUE,
  width = NULL,
  height = NULL,
  ...
)

Value

geom layer

Arguments

mapping

aes mapping

data

data

stat

stat

position

position

inherit.aes

logical, whether inherit aes from ggplot()

na.rm

logical, whether remove NA values

by

one of 'width' or 'height'

nudge_x

horizontal adjustment to nudge image

nudge_y

vertical adjustment to nudge image

use_cache

logical, whether to use image caching for better performance (default: TRUE)

width, height

Image width and height in native panel units, matching the plotting units used by the size/by behavior. They can be mapped per row via aes(width = ..., height = ...) or set for the whole layer. They override size (and therefore also size = Inf and by):

  • only width is provided, the height is derived from the image ratio;

  • only height is provided, the width is derived from the image ratio;

  • both are provided, the image is drawn in exactly that box, which may distort it when the ratio of the box differs from the image ratio.

coord_fixed() controls the physical aspect of the panel; it does not reinterpret these values. Values that are NA, not finite or not positive are ignored, and the size/by behavior is used for the affected image.

...

additional parameters

Author

Guangchuang Yu

Examples

Run this code
if (FALSE) {
library("ggplot2")
library("ggimage")
set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                image = sample(c("https://www.r-project.org/logo/Rlogo.png",
                                "https://jeroenooms.github.io/images/frink.png"),
                              size=10, replace = TRUE)
               )
# With caching enabled (default)
ggplot(d, aes(x, y)) + geom_image(aes(image=image))

# With caching disabled
ggplot(d, aes(x, y)) + geom_image(aes(image=image), use_cache=FALSE)

# Per-row image size, via the `width` and `height` aesthetics
ggplot(d, aes(x, y)) +
    geom_image(aes(image=image, width=abs(x)/10, height=abs(y)/10))

# Only one of them: the other dimension keeps the ratio of the image
ggplot(d, aes(x, y)) + geom_image(aes(image=image, width=abs(x)/10))
}

Run the code above in your browser using DataLab