How to use an image as a point in ggplot?

ggplot2, ggproto, r

Solution

There is a library called `ggimage` to do that. See an intro vignette here

You just have to add a column to your `data.frame` with the address of the images, which can be stored on the web or locally on your computer and then you can use the `geom_image()`:

library("ggplot2")
library("ggimage")

# create a df

set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                image = sample(c("https://www.r-project.org/logo/Rlogo.png",
                                 "https://jeroenooms.github.io/images/frink.png"),
                               size=10, replace = TRUE)
                )
# plot2
  ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05)

ps. Note that `ggimage` depends on EBImage. So to install `gginamge` I had to do this:

# install EBImage
  source("https://bioconductor.org/biocLite.R")
  biocLite("EBImage")
# install ggimage
  install.packages("ggimage")

Problem

Is there some way to use a specific small image as a point in a scatterplot with ggplot2. Ideally I will want to resize the images based on an variable. Here's an example: ``` library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(aes(size = qsec, shape = factor(cyl))) ``` So I basically want to know if there is a way to supply a specific image as the shape?

Original source

Related problems