3

我无法弄清楚如何使用ggimage.

很清楚如何将不同的图像设置为单一颜色(来自 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()(和/或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)

我非常感谢您尝试解决此问题的帮助。

4

1 回答 1

1
    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)))
于 2021-10-13T12:27:11.917 回答