0

I am trying to make an animated histogram with the following code:

library(ggpubr)
library(gganimate)

p <- gghistogram(df, x = "Idade", bins = 30,
   add = "mean", rug = T,
   color = "Género", fill = "Género",
   palette = c("#0073C2FF", "#FC4E07", "grey"), 
   xlab ="Idade (anos)", ylab = "(n)", 
   title = "Distribuição de Idades") + 
  theme(legend.position = "right")+ 
  theme_ipsum_rc(grid="Y",base_size = 16,axis_title_size = 14)+
  transition_states(Idade, wrap = F) + shadow_mark() + enter_grow() +  exit_fade() 

animate(p,  nframes=100, fps = 10, renderer = gifski_renderer(loop = FALSE))

but I am getting different darker blue and red bars (ghosts) like this:

Gosth histrogram bars in gganimante

I can't figure it out. Any ideas on how to remove the darker bars? Thanks!

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
JPMD
  • 644
  • 1
  • 7
  • 19
  • 1
    Looks like overlapping bars, but without a [reproducible dataset](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), it's hard to give very specific advice... – Z.Lin Jun 17 '20 at 06:24

1 Answers1

1

For a given value of x and genero, you have multiple values of y in your dataframe df. The darkshade represents the lower value and lighter shade represents the higher value. If you have two values, you will see two shades, for 3 values you will see 3 shades, and so on. You can subset the dataframe df for a single value of that variable resulting in unique combination of x, y and genero. Then you will get only one shade. Without a sample dataframe, it cannot be confirmed.

YBS
  • 19,324
  • 2
  • 9
  • 27