View source: R/ggplot-geom-magick.R
| geom_magick | R Documentation |
Reads an image with magick, applies optional processing, and uses the result as the graphical shape for points in a plot.
This is useful when you want to replace the usual point symbols with arbitrary images while keeping full control over their placement, size, and interpolation.
geom_magick(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
magick = NULL,
magick_params = list(),
interpolate = TRUE,
na.rm = FALSE,
show.legend = NA,
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 |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
These dots are for future extensions and must be empty. |
magick |
A function (purrr-style formula is accepted) that takes an
|
magick_params |
Additional arguments passed on to |
interpolate |
A logical value indicating whether to linearly interpolate the image (the alternative is to use nearest-neighbour interpolation, which gives a more blocky result). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_magick() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | x | |
| • | y | |
| • | image | |
| • | alpha | → NA |
| • | angle | → 0 |
| • | fill | → NA |
| • | group | → inferred |
| • | hjust | → 0.5 |
| • | size | → via theme() |
| • | vjust | → 0.5 |
Learn more about setting these aesthetics in vignette("ggplot2-specs").
set.seed(123)
d <- data.frame(
x = rnorm(10),
y = rnorm(10),
image = "https://jeroenooms.github.io/images/frink.png",
fill = sample(c("A", "B", "C", "D"), 10, replace = TRUE),
alpha = rnorm(10, mean = 0.5, sd = 0.1)
)
d$alpha <- pmax(pmin(d$alpha, 1), 0)
ggplot(d, aes(x, y)) +
geom_magick(aes(image = image, fill = fill, alpha = alpha))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.