# \donttest{
# image glyph
if(require("png")) {
img_path <- list.files(file.path(find.package(package = 'ggmulti'),
"images"),
full.names = TRUE)
Raptors <- png::readPNG(img_path[2L])
Warriors <- png::readPNG(img_path[3L])
pg <- ggplot(data = data.frame(x = 1:2, y = rep(1, 2)),
mapping = aes(x = x, y = y)) +
geom_image_glyph(images = list(Raptors,
Warriors),
imagewidth = rep(1.2, 2),
imageheight = c(0.9, 1.2)) +
coord_cartesian(xlim = extendrange(c(1,2)))
pg
# query the images (a numerical array)
build <- ggplot2::ggplot_build(pg)
# `imageRaptors` and `imageWarriors` are three dimensional
# arrays (third dimension specifying the plane)
imageRaptors <- build$data[[1]]$images[[1]]
imageWarriors <- build$data[[1]]$images[[2]]
if(require("grid")) {
grid.newpage()
grid.raster(imageRaptors)
grid.newpage()
grid.raster(imageWarriors)
}
# THIS IS SLOW
mercLogo <- png::readPNG(img_path[1L])
p <- ggplot(mapping = aes(x = hp, y = mpg)) +
geom_point(
data = mtcars[!grepl("Merc", rownames(mtcars)), ],
color = "skyblue") +
geom_image_glyph(
data = mtcars[grepl("Merc", rownames(mtcars)), ],
images = mercLogo,
imagewidth = 1.5
)
p
}
# }
Run the code above in your browser using DataLab