When using raster objects directly you need to somehow define how it should
be located in resized in the plot. These function can be used to inform the
filter on how it should be used. They only work on raster
type object, so
cannot be used around functions or layer id's.
A raster
or nativeRaster
object or an object coercible to
a raster
object
Should the raster be positioned according to the canvas or the current viewport
Where should the raster be placed relative to the alignment area
A unit or numeric vector giving an additional offset relative to the anchor. Positive values moves right/down and negative values move left/up
Should every other repetition be flipped
The input with additional information attached
library(ggplot2)
logo <- as.raster(magick::image_read(
system.file('help', 'figures', 'logo.png', package = 'ggfx')
))
# Default is to fill the viewport area, preserving the aspect ratio of the
# raster
ggplot(mtcars) +
with_blend(
geom_point(aes(mpg, disp)),
logo
)
# But you can change that with these functions:
ggplot(mtcars) +
with_blend(
geom_point(aes(mpg, disp)),
ras_place(logo, 'vp', 'bottomright')
)
# Here we tile it with flipping, centering on the middle of the canvas
ggplot(mtcars) +
with_blend(
geom_point(aes(mpg, disp)),
ras_tile(logo, anchor = 'center', flip = TRUE)
)