thomasp85 / gganimate

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

can we have 2 shadow_* in one animation? #90

Closed ginolhac closed 6 years ago

ginolhac commented 6 years ago

Hi,

let me say again one more time: thank you for such nice packages you develop! They are really awesome.

I am playing with some real biological time-series data, RNA-seq of cell differentiation. We want to see cellular differentiation though time, and gganimate is perfect for this. The only issue is that I'd like to have both:

If shadow_trail() is on, the shadow_wake() does not work

library(tidyverse)
#devtools::install_github("thomasp85/gganimate")
library(gganimate)
df <- read_tsv("https://biostat2.uni.lu/dgerard/diff_data.tsv.gz", col_types = cols())
df %>% 
  ggplot(aes(x = coord.Dim.1, y = coord.Dim.2, group = replicate)) +
  geom_point(aes(colour = factor(t)), size = 4) +
  geom_point(data = function(x) select(x, id, t:coord.Dim.2_mean) %>% distinct(),
            aes(x = coord.Dim.1_mean, y = coord.Dim.2_mean, group = id), alpha = 0) +
  geom_text(data = function(x) select(x, cell:coord.Dim.2_mean) %>% filter(t %in% range(t)) %>% distinct() %>%
              mutate(cell = recode(cell, O = "Osteo", A = "Adipo", ST2 = "MPC")),
            aes(x = coord.Dim.1_mean, y = coord.Dim.2_mean, colour = factor(t), label = cell), size = 6) +
  transition_components(id, t) +
  # FIXME shadow_wake does not work when trail is on
  shadow_wake(wake_length = 0.25, size = TRUE, exclude_layer = 3) +
  shadow_trail(distance = 0.01, size = 2, colour = "grey", alpha = 0.3, exclude_layer = c(1, 3)) +
  theme_classic(14) +
  scale_colour_viridis_d(guide = FALSE, direction = -1) +
  labs(title = "time: {frame_time} (days)",
       x = "PC1, 39.3% var",
       y = "PC2, 31.6% var")  -> plot_diff
animate(plot_diff, nframes = 100)

Created on 2018-07-09 by the reprex package (v0.2.0).

So my question, can we have 2 shadow_* in one animation?

thomasp85 commented 6 years ago

You can't (right now)

I might consider adding it, but it would require a sizeable amount of code change...

ginolhac commented 6 years ago

Ok, I understand. I think I will close then, as it was more for fun than for an actual pedagogical need.

You might have seen that I reduced the distance of shadow_trail to see as much as possible the trajectory. A shadow_line or shadow_ribbon would be more relevant here. A continuous ribbon where the alpha would help to see the speed of transitions. Less transparency = slower motion.

(right now, I am playing with animating pictures of the actual cells, it is almost working, might open another issue if I don't manage)