# add interactive raster annotation to a ggplot -------
library(ggplot2)
library(ggiraph)
# Generate data
rainbow <- matrix(hcl(seq(0, 360, length.out = 50 * 50), 80, 70), nrow = 50)
p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
annotation_raster_interactive(
rainbow,
15,
20,
3,
4,
tooltip = "I am an image!"
)
x <- girafe(ggobj = p)
if (interactive()) {
print(x)
}
# To fill up whole plot
p <- ggplot(mtcars, aes(mpg, wt)) +
annotation_raster_interactive(
rainbow,
-Inf,
Inf,
-Inf,
Inf,
tooltip = "I am an image too!"
) +
geom_point()
x <- girafe(ggobj = p)
if (interactive()) {
print(x)
}
Run the code above in your browser using DataLab