I have created a multiple panel plot using facet_wrap
in ggplot2 and would like to add the different images into each panel.
annotation_custom
could be used insert an image into ggplot2, but it is the same for all panels.
This is an example to add R logo
library(ggplot2)
# Create dataset
df <- data.frame(
x = rep(seq(1, 5), times = 2),
y = rep(seq(1, 5), times = 2),
z = rep(seq(1, 2), each = 5)
)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
g <- rasterGrob(img, interpolate=TRUE)
ggplot(df) +
geom_point(aes(x, y)) +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
facet_wrap(~z)
img2
is generated from img
.
img2 <- img * 0.5
Is it possible to insert different images in ggplot2 (i.e. img
to panel 1 and img2
to panel 2)?
Thanks for any suggestion. Please let me know if my question is not clear.