geom_chronochRtImage {chronochrt}R Documentation

Add image labels to plot

Description

Plot images in a ggplot2 object. Supported file types are: .png, .jpg, .tif, .bmp., .svg (see image_read for further details).

Usage

geom_chronochRtImage(mapping = NULL, data = NULL, inherit.aes = TRUE, ...)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

...

Other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like height = 1.

Details

The images are provided by their paths (local files or URLs) via the aesthetic image_path. Rows with invalid file paths are silently dropped, invalid URLs will throw an error.

The absolute size in cm of the images can be specified via the aesthetics height and width. If only one is specified, the image is scaled under preservation of its aspect ratio. If both are given, the image might appear distorted. See examples for further details.

Value

Layer of a ggplot2 object.

Aesthetics

geom_ChronochRtImage() understands the following aesthetics (required aesthetics are in bold):

See Details for how these aesthetics work.

Author(s)

This geom is a modified version of the geom_custom() from Baptiste AuguiƩ's egg package.

Examples


library(ggplot2)

# Create example data
data <- data.frame(x = c(2, 4), y = c(2, 4),
                   image_path = "https://www.r-project.org/logo/Rlogo.png",
                   height = c(1,2), width = c(3,0.5))

q <- ggplot(data) + lims(x = c(0, 6), y = c(0, 6))

# Without size specifications
q + geom_chronochRtImage(aes(image_path = image_path, x = x, y = y))

# Scale images to individual heights/widths by specifying one of them:
q + geom_chronochRtImage(aes(image_path = image_path, x = x, y = y, height = height))

# Scale images to uniform height/width (i.e. independent of input data):
q + geom_chronochRtImage(aes(image_path = image_path, x = x, y = y, height = 1))

# Specifying height and width might result in distorted images:
q + geom_chronochRtImage(aes(image_path = image_path, x = x, y = y, height = height, width = width))

[Package chronochrt version 0.1.3 Index]