View source: R/chronochrt_geom_imagelabels.R
geom_chronochRtImage | R Documentation |
Plot images in a ggplot2 object. Supported file types are: .png
,
.jpg
, .tif
, .bmp.
, .svg
(see
image_read
for further details).
geom_chronochRtImage(mapping = NULL, data = NULL, inherit.aes = TRUE, ...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
inherit.aes |
If |
... |
Other arguments passed on to |
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.
Layer of a ggplot2 object.
geom_ChronochRtImage()
understands the following
aesthetics (required aesthetics are in bold):
image_path
x
y
group
height
width
See Details for how these aesthetics work.
This geom is a modified version of the geom_custom()
from Baptiste AuguiƩ's egg package.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.