Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201977

Issue when rendering an animated plot using gganimated

$
0
0

I'm using the gganimate package in R to animate my plot. It works well but the flags are repeated and the first three images get stuck also.

data_rates_plot %>% 
  ggplot(aes(x = Year, y = Rate, group = factor(Country))) +
  geom_line(aes(color = factor(Country))) +
  geom_image(aes(image=Image)) +
  transition_reveal(Year) +
  scale_color_manual(values=c("#34ba5c", "#000000", "#db0000", "#050c75")) +
  theme(element_line('black'),
        axis.line = element_line(color = "black",  size = 0.5, linetype = "solid"),
        plot.background = element_rect(fill = '#fff7e6'), panel.background = element_rect(fill = '#fff7e6'),
        panel.grid = element_line(colour = NULL, linetype = 3),
        panel.grid.major = element_line(colour = "black"),
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank() ,plot.title = element_text(hjust = 0, face = "bold"),
        plot.margin = unit(c(1, 1, 1, 1), "lines"),
        strip.background = element_rect(),
        legend.position = "none") +
  labs(title = "Ratio de homicidios (1990-2017)", x = "Año", y = "Ratio (núm. homicidios/100.000 hab.)")

This is a sampling of the dataset I'm using to plot:

> head(data_rates_plot)
  Country Year     Rate Continent                                                                   Image
1  Brazil 1994 28.59261  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png
2  Brazil 2003 32.46278  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png
3  Brazil 2015 30.32380  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png
4  Brazil 1991 26.23049  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png
5  Brazil 1993 27.26052  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png
6  Brazil 2000 32.13900  Americas https://upload.wikimedia.org/wikipedia/commons/0/01/Brazil_flag_300.png

enter image description here

Filtering to just Brazil:

enter image description here

dput(data_rates_plot %>% select(Country, Year, Rate) %>% filter(Country == "Brazil")):

structure(list(Country = c("Brazil", "Brazil", "Brazil", "Brazil", 
"Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", 
"Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", 
"Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", "Brazil", 
"Brazil", "Brazil", "Brazil"), Year = c(1994L, 2003L, 2015L, 
1991L, 1993L, 2000L, 2017L, 1990L, 2002L, 1997L, 2012L, 1995L, 
1992L, 2011L, 2004L, 2001L, 2013L, 1996L, 2006L, 2009L, 2014L, 
1999L, 2005L, 2010L, 2016L, 1998L, 2007L, 2008L), Rate = c(28.5926053974604, 
32.4627790546635, 30.3237998934026, 26.2304907371429, 27.2605158574606, 
32.1390025655279, 30.1328892734601, 26.7440815134982, 32.7898675004014, 
31.1361250032559, 30.6407022936813, 30.4476309648573, 26.0500124795172, 
30.2078811223668, 31.6613393520385, 32.4090823805319, 30.7139681276347, 
30.5758007548371, 30.5130381597837, 30.0623192371181, 30.686318995567, 
31.679684049261, 30.7334658622574, 30.145587333775, 30.5099622110466, 
31.5382871119106, 30.1461623438502, 29.9688608949252)), row.names = c(NA, 
-28L), class = "data.frame")

Anybody knows what's happening?


Viewing all articles
Browse latest Browse all 201977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>