thomasp85 / gganimate

A Grammar of Animated Graphics
https://gganimate.com
Other
1.94k stars 308 forks source link

gganimate used with treemapify does not animate according to date. #351

Closed ambijat closed 3 years ago

ambijat commented 4 years ago

I have been using date column to see transition of treemap that shows area as frequency of a tweet that is tweeted number of times. The dates are not uniformly distributed. I use transition_time and there is a situation where if for each date the tweets are 2 then treemap some times shows 2 or more than 2 in some transition. Why this is happening.

ambijat commented 4 years ago

F.GIF f Q.GIF q

The two images are the transition of the same tweet data, where 1) image f.gif is based on date column having discrete dates, and 2) q.gif is based on integer index column created for dates. q.gif is the desired image but the display of frame_time of f.gif is the needed one.

ambijat commented 4 years ago

t7b4.txt The data used for the gganimate is here.

ambijat commented 4 years ago

Code for the animation

`library(gganimate)

q <- ggplot(t7b4, aes(area = V1, fill = text, label = text)) + geom_treemap() + geom_treemap_text(place = "centre", grow = T, reflow = T, colour = "white", min.size = 0) + transition_time(trn) + ease_aes('linear') + theme(legend.position = 'none') + labs(title = "Tweets: {frame_time}")

animate(q, length(unique(t7b4$trn)), .3, width = 700)

f <- ggplot(t7b4, aes(area = V1, fill = text, label = text)) + geom_treemap() + geom_treemap_text(place = "centre", grow = T, reflow = T, colour = "white", min.size = 0) + transition_time(date) + ease_aes('linear') + theme(legend.position = 'none') + labs(title = "Tweets: {frame_time}")

animate(f, length(unique(t7b4$date)), .3, width = 700)

`

thomasp85 commented 3 years ago

there was an issue with transition time were the data might appear multiple times if there were less frames than unique keyframes. This has been fixed in devel

ambijat commented 3 years ago

Thanks, I shall check it out.

On Tue, Mar 16, 2021, 5:13 PM Thomas Lin Pedersen @.***> wrote:

there was an issue with transition time were the data might appear multiple times if there were less frames than unique keyframes. This has been fixed in devel

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/thomasp85/gganimate/issues/351#issuecomment-800188211, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKRMGKXLIBL2U7RGJ2ZTEJTTD477ZANCNFSM4I3WYSCA .

thomasp85 commented 3 years ago

The weird flickering is a gifski issue, not anything to do with gganimate...

Have you installed the dev version of gganimate?

ambijat commented 3 years ago

sorry I accidentally delete my post. But let me continue on this. I have sorted this out.

ambijat commented 3 years ago

I have only updated via Fedora not knowing whether the latest version was installed. But my gif is just as fine. The code used is as below.

f <- ggplot(t7b42, aes(area = V1, fill = text, label = text)) + 
  geom_treemap() + 
  geom_treemap_text(place = "centre",
                    grow = T,
                    reflow = T,
                    colour = "white",
                    min.size = 0) +
  transition_time(date) +
  ease_aes('linear') +
  theme(legend.position = 'none') +
  labs(title = "Tweets: {frame_time}")

animate(f, length(unique(t7b42$date)), fps=.5, width = 700)

The only blunder that I came to know is to not to use frame_along. As it will keep piling tiles in successive frames making the last frame a clutter of all tweet tiles.

f

ambijat commented 3 years ago

Hi! today I again tried to take a second look at my code on a different sample of data and my results were again erratic. I am putting my data and the gif for perusal. And, the code is given below. You can see there is an alternate pattern of single tile and double tile, whereas the data has all the single day tiles. So, there should be a single tile for each transition. And, whenever there is a double tile then the date jumps accordingly.

q <- ggplot(t7b4, aes(area = V1, fill = text, label = text)) + 
  geom_treemap() + 
  geom_treemap_text(place = "centre",
                    grow = T,
                    reflow = T,
                    colour = "dark blue",
                    min.size = 0) +
  transition_time(date) +
  ease_aes('linear') +
  theme(legend.position = 'none') +
  labs(title = "Tweets: {frame_time}")

animate(q, length(unique(t7b4$date)), fps=.4, width = 700)

t7b4.txt q

ambijat commented 3 years ago

my final understaning is that if there are gaps in dates then the gganimate goes haywire. It only works if dates are smooth in continuity. This needs to be tackled.

thomasp85 commented 3 years ago

transition_time() is a keyframe type transition, so yes, data point that doesn't exist in the next keyframe will be removed... You may want to use transition_reveal()? Though I'm not sure exactly what you are going for...

ambijat commented 3 years ago

my goal is too display 4 leading tweets as a single frame with tile sizes according to the number of times they have been tweeted. So the largest tile shall of the tweet that has been retweeted maximum number times. I can choose top 4 or top 5 or top 6 based on their importance. So say for 14 days I have a set of 4 tweets per day. And then there shall be 14 frames of transition giving tweet tiles based on retweet size. But if there is a gap in dates then gganimate fumbles. Tries to pull tiles onto other dates or at times rendering gets jittery.

ambijat commented 3 years ago

transition_reveal gives entirely different result with each transition all tiles getting accumulated in the frame. Something not at all intended. See code and gif.

z<- ggplot(t7b42, aes(area = V1, fill = text, label = text)) + 
  geom_treemap() + 
  geom_treemap_text(place = "centre",
                    grow = T,
                    reflow = T,
                    colour = "white",
                    min.size = 0) +
  transition_reveal(date) +
  ease_aes('linear') +
  theme(legend.position = 'none') +
  labs(title = "Tweets: {frame_along}")

animate(z, length(unique(t7b42$date)), fps=.5, width = 700)

z

thomasp85 commented 3 years ago

Can you provide an example that is minimal, and clearly show (maybe with an annotated screenshot) where the output is not how you want it to be, because I cannot see how this is wrong, since I don't understand what you want.

Do note that if this is because you have time points that are missing a data point and you want that data to not disappear then that is not going to happen - this is part of the design of transition_time()

ambijat commented 3 years ago

Pleasee see this, I have tried to be clear as much as possible. https://youtu.be/KlXDrDh7ny0 Also, the data is being appended here. t7b4.txt

thomasp85 commented 3 years ago

So, is transition_time() now behaving as it should (except for the green flicker which is a gifski issue not a gganimate issue)

transition_reveal() is doing what it should but is not what you wanted - I just didn't understand your use case when I proposed it

ambijat commented 3 years ago

"So, is transition_time() now behaving as it should (except for the green flicker which is a gifski issue not a gganimate issue)". The answer is Yes and No. I say this because it is Yes only if the dates are in continuity. A gap in dates brings the clutter of tiles and dates start jumping.

thomasp85 commented 3 years ago

Can you show an example of that - I still don't understand neither what you mean with "gap" nor "clutter"

ambijat commented 3 years ago

I have prepared the second video to demonstrate the problem. https://youtu.be/bDwZ7KNNS7Y

thomasp85 commented 3 years ago

Ok, I see it now...

The underlying issue is that you are using transition_time with some very big gaps which forces multiple time points to occupy the same frame. You'll either need to increase the number of frames in the animation or use transition_states instead. The latter is probably a good idea anyway since you are treating your time dimension as discrete

ambijat commented 3 years ago

Tried transition_states() results were not as expected. Some slides skipped and the transition restarted in the viewer. Transition_reveal has done a better job. Though the problem with reveal was the fill and subgroup did not work so as to collate the tiles.

ambijat commented 3 years ago

I have made a discovery by chance. I am using transition_time, and the rendering problem which I have been facing was solved with a unique step. I had values South.Korea and United.Kingdom in column country and I am using the latter as label for tiles. But when I modified these two values as SouthKorea and UK the problem did not occur. It seems that period in label values has some problem while rendering. Please let me know if you need data and code to try. I am avoiding posting for the discussion has become pretty long.