我正在尝试将自己的图像用于geom_point,我可以读取这些内容。我知道geom_point允许您通过简单地编写shape = 243来选择许多形状(超过300种),但是我想要自己的图像(例如徽标)。
当我没有指定color = factor(Name)时,它可以按预期工作。当我确实指定线条的颜色时,图像将变为纯色。我希望这条线是彩色的,所以有什么办法解决吗?谢谢!
library(gganimate)
library(gifski)
library(png)
library(ggimage)
Step <- 1:50
Name <- rep("A",50)
Image <- rep(c("https://jeroenooms.github.io/images/frink.png"),50)
Value <- runif(50,0,10)
Final <- data.frame(Step, Name, Value, Image)
a <- ggplot(Final, aes(x = Step, y = Value, group = Name, color = factor(Name))) +
geom_line(size=1) +
geom_image(aes(image=Image)) +
transition_reveal(Step) +
coord_cartesian(clip = 'off') +
theme_minimal() +
theme(plot.margin = margin(5.5, 40, 5.5, 5.5)) +
theme(legend.position = "none")
options(gganimate.dev_args = list(width = 7, height = 6, units = 'in', res=100))
animate(a, nframes = 100)
这是您要找的东西吗?
我只是将color = factor(Name)
立场改为geom_line
陈述。
如果在第一行中使用color = factor(Name)
with ggplot
,它将影响整个图。因此,使用此语句时应格外小心。
a <- ggplot(Final, aes(x = Step, y = Value, group = Name)) +
geom_line(size=1, aes(color = factor(Name))) +
geom_image(aes(image=Image)) +
transition_reveal(Step) +
coord_cartesian(clip = 'off') +
theme_minimal() +
theme(plot.margin = margin(5.5, 40, 5.5, 5.5)) +
theme(legend.position = "none")
为了方便起见,我拍摄了这张照片。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句