如何使用 geom_image() 的多种颜色

How to use multiple colors with geom_image()

我无法弄清楚如何使用 ggimage 突出显示多种颜色。

很清楚如何将不同的图像设置为一种颜色(from vignette):

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

set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                z = sample(c("A","B","C","A","B","C","A","B","C","A")),
                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), color="firebrick")

我在示例中引入了另一列 z,因为我正在使用的数据集有一个变量,我想对其应用 color 美学。

我尝试了通常如何在 ggplot() (and/or geom_point()) 调用中设置它,但我没有得到我想要的输出:

ggplot(d, aes(x, y)) + geom_image(aes(image=image), color=d$z) 

Error in col2rgb(color) : invalid color name 'test'

它不接受多种颜色吗?

ggplot(d, aes(x, y)) + geom_image(aes(image=image), color = c("blue","red","green"))

我也试过指定三种颜色 RColorBrewer:

library(RColorBrewer)

my_color <- brewer.pal(3, "Set1")
ggplot(d, aes(x, y)) + geom_image(aes(image=image), color = my_color)

非常感谢你帮助解决这个问题。

    set.seed(2017-02-21)
    d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                z = sample(c("A","B","C","A","B","C","A","B","C","A")),
                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,group=z)) + geom_image(aes(image=image,color=factor(z)))