I'm drawing a scatterplot where I'd like to highlight different observations as time passes. Sometimes, these observations are close together, so I'm using geom_label_repel to do so. I'd also like to use enter_fade and exit_fade in order to make smoother the transition between phases of the animation.
I see from elsewhere (eg here) that the position of the geom_label_repel can be made consistent with the use of a seed. However, this isn't working for me with enter_fade and exit_fade: the geom_label_repel jumps around as the labels enter and exit.
Is there a way that the geom_label_repel can stay where it is through these phases?
Here's an example of how I've attempted to implement this, which hopefully will illustrate the problem I'm running into.
set.seed(24601)
library(stringi)
library(tidyverse)
library(gganimate)
library(ggrepel)
x <-
rnorm(100, 0, 1)
y <-
rnorm(100, 0, 1)
names <-
stri_rand_strings(100,
5)
categories <-
rep(c("a", "b", "c", "d", "e"), 5)
ggplot(data.frame(x, y, names, categories)) +
aes(x = x,
y = y) +
geom_point(data = . %>%
select(- categories)) +
geom_label_repel(aes(label = names,
group = categories),
seed = 24601) +
transition_states(categories) +
enter_fade() +
exit_fade()