I am trying to use my own image for geom_point, something I can just read in. I am aware geom_point allows you to choose many shapes (well over 300) by simply writing shape = 243 but I want my own image such as a logo.
When I have not specified color = factor(Name) then it works as expected. When I do specify the colour of the line then the image becomes a solid single colour. I want this line to be coloured so is there any way around this? Thanks!
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)
In order to save the animation to a specific location, you can use the anim_save() function which, like ggplot2::ggsave , defaults to taking the last rendered animation and writes it to a file.
If you need to save the animation for later use you can use the anim_save() function. It works much like ggsave() from ggplot2 and automatically grabs the last rendered animation if you do not specify one directly.
Is this what your are looking for ?
I Just changed the color = factor(Name)
position to geom_line
statement.
If you use color = factor(Name)
with ggplot
in first row, it will affect to whole plot. So you should take care when using this statement.
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")
For convenience, i captured the picture .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With