Skip to content

Instantly share code, notes, and snippets.

@ginolhac
Last active June 15, 2018 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ginolhac/d7651fb03b802e65c6e9aa06ccfe4b86 to your computer and use it in GitHub Desktop.
Save ginolhac/d7651fb03b802e65c6e9aa06ccfe4b86 to your computer and use it in GitHub Desktop.
gganimate tSNE
library(gganimate)
# rds object comes from this tutorial
# https://ulhpc-tutorials.readthedocs.io/en/latest/maths/R/#parallel-computing-using-hpc
res_tib <- read_rds("tsne_future.rds")
res_tib %>%
unnest(tsne) %>%
select(-output) %>%
group_by(perplexities) %>%
mutate(n = row_number()) %>%
filter(perplexities < 400) %>%
filter(n <= 5000) -> tib_light
tictoc::tic("tweening")
tib_light %>%
ggplot(aes(x = V1, y = V2, group = n, colour = factor(c))) +
geom_point(data = function(x) filter(x, c == 0), colour = "grey50", alpha = 0.2) +
geom_point(data = function(x) filter(x, c != 0), alpha = 0.6) +
transition_components(id = n, time = perplexities, exit_length = 15) +
ease_aes('cubic-in-out') +
labs(title = "perplexities: {ceiling(frame_time)}") + # closest_state for transition states, frame for transition_components
labs(colour = "cluster") +
coord_equal() +
theme_minimal(14) +
theme(legend.position = "bottom") -> tib_anim
tictoc::toc()
tictoc::tic("animate")
tib_gif <- animate(tib_anim, nframes = 800, fps = 10)
tictoc::toc()
tib_gif
magick::image_write(tib_gif, "tsne_600_component.gif")
@ginolhac
Copy link
Author

tsne_110_component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment