thomasp85 / gganimate

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

transition_manual and transition_time fail in geom_streamline #121

Open eliocamp opened 6 years ago

eliocamp commented 6 years ago

I've seen your call for stress testing gganimate with weird geoms and wanted to comply. Package metR has geom_streamline() which computes streamlines from a vector field. One of the computed values is step which is a numeric value representing the integration step. With the old gganimate, I could map this variable to frame and it worked, but now it seems to be broken.

Here's a reprex

library(metR)
library(ggplot2)
library(gganimate)

Here’s the basic plot showing also how the step variable works.

(g <- ggplot(seals, aes(lat, long)) +
    geom_streamline(aes(dx = delta_long, dy = delta_lat, color = stat(step)), L = 5))

Using transition_manual seemed like the most logical transition

g + transition_manual(step)
#> Error in data.frame(previous_frame = c("", all_frames[-length(all_frames)]), : arguments imply differing number of rows: 1, 0

Or also transition_time

g + transition_time(step)
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error in seq.default(range[1], range[2], length.out = nframes): 'from' must be a finite number

Created on 2018-08-02 by the reprex package (v0.2.0).

thomasp85 commented 6 years ago

Thanks. The problem here is that I have yet to add support for computed variables in the different transition functions... This will come and it is nice to have a use case

dcfaltesek commented 5 years ago

We have produced the same error in gganimate using this code:

`T <-ggplot(NOISEY, aes(month_day, hour, group = month))+
  geom_line()+
  transition_reveal(month, month_day)

animate(T)`

the resulting error Error in seq.default(range[1], range[2], length.out = nframes) : 'from' must be a finite number

NOISEY is a dataset is a collection of local crime reports, month_day is the day of the month int, month is month dbl, hour is int.

We wrote this to mirror:

`p <- ggplot(airquality, aes(Day, Temp, group = Month)) + geom_line() + transition_reveal(Month, Day)

animate(p)`

Which produces a successful plot.

We have also tried as.numeric() and using only numeric elements of our plot.

dcfaltesek commented 5 years ago

Perhaps to answer my own question, gganimate seems to really need numbery numbers

The following examples adapt another dataset and create random data

`??airquality

p <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_line() +
  transition_reveal(Month, Day)

animate(p)

library(ggvis)
??cocaine

p <- ggplot(cocaine, aes(month, price, group = state)) +
  geom_line() +
  transition_reveal(month, month)

animate(p)

A<-sample(1:100, 50, replace=TRUE)
B<-sample(1:100, 50, replace=TRUE)
C<-sample(1:3, 50, replace=TRUE)
D<-sample(1:3, 50, replace=TRUE)
G<-data.frame(A,B,C,D, stringsAsFactors = FALSE)
View(G)

p <- ggplot(G, aes(A, B, colour = D, group = C)) +
  geom_line() +
  transition_reveal(A, A)

animate(p)`

In short, the transition vars really seem to need to be numeric.