Last active
June 15, 2018 09:07
-
-
Save ginolhac/d7651fb03b802e65c6e9aa06ccfe4b86 to your computer and use it in GitHub Desktop.
gganimate tSNE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Author
ginolhac
commented
Jun 15, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment