ggimage: Custom image from computer rather than from web

MYa*_*208 4 r ggplot2 ggimage

The following graph can be produced from the R code given below. The images used in the graph are fetched from website. I'm wondering how to use images from computer.

在此输入图像描述

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

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)
                )

ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05)
Run Code Online (Sandbox Code Playgroud)

Sci*_*rlo 5

非常简单,您只需设置保存要使用的 .png 文件的目录即可:

library("ggplot2")
library("ggimage")
set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                image = sample(c("C:/YourDirectory/juventus.png",
                                 "C:/YourDirectory/sampdoria.png"),
                               size=10, replace = TRUE)
)

ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05)
Run Code Online (Sandbox Code Playgroud)

你会得到以下结果: 在此输入图像描述