ggimage
ggimage copied to clipboard
geom_image(): flip and rotate an image
Is it possible to rotate/flip/fop an image with geom_image()
?
I would like to get the mirror-image based on a binary variable. For example, given that z
is either "A"
or "B"
have points which are "B" be the mirror-image.
library("ggplot2")
library("ggimage")
set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
y = rnorm(10),
z = sample(c("A","B")),
image = sample(c("https://www.r-project.org/logo/Rlogo.png", "https://jeroenooms.github.io/images/frink.png"), size=10, replace = TRUE))
currently, you can use something like this:
ggplot(subset(d, z=="A"), aes(x,y, image=image)) +
geom_image(angle=45) +
geom_image(angle=-45, data=subset(d, z=="B"))
The images used to have a background that matches the plot (grey) but when you apply your suggested work-around to rotate the images there is now white background visible which is ugly. I tried setting theme_bw()
which kind of works; however, you still see a white background box surrounding fink and the Rlogo which overlays the plot background.
Guessing, it's currently not possible to get a mirror-image (like image_flop()
from the magick package) according to a subset?
try:
ggplot(subset(d, z=="A"), aes(x,y, image=image)) +
geom_image(image_fun=image_flop) +
geom_image(data=subset(d, z=="B"))
Has angle
been deprecated? What's the suggested approach for rotating images with geom_image
?