use*_*588 6 animation r image ggplot2 gganimate
我正在尝试将我自己的图像用于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)
Run Code Online (Sandbox Code Playgroud)
小智 2
这是您正在寻找的吗?
我刚刚将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")
Run Code Online (Sandbox Code Playgroud)
为了方便,我拍了张照片。