3

I have a fairly simple problem where I want to create a gif which loops through departure_hour and colors the lines based on link volumes. One caveat is the number of rows between states (i.e. departure_hour) may be different.

Here is the code I am trying:

vol <- ggplot() + 
              geom_sf(data = test, aes(color=link_volume)) + 
              scale_color_distiller(palette = "OrRd", direction = 1) +
              ggtitle("{frame_time}") +
              transition_time(departure_hour) +
              ease_aes("linear") +
              enter_fade() +
              exit_fade()
animate(vol, fps = 10, width = 750, height = 450)

However, when I do this I am getting the error:

Error in tween_state(as.data.frame(full_set$from), as.data.frame(full_set$to),: 
  identical(classes, col_classes(to)) is not TRUE

First, I do not understand if the error is referring to column classes or color classes? If it is color classes am I correct in assuming that the color scales between each plot may be different and that is the reason for this error?

Second, how do I fix this error? There seems to be just one more question on this issue and it has no solution.

Sample data:

> dput(head(test,5))
structure(list(linkid = c(12698L, 26221L, 36429L, 36430L, 47315L
), departure_hour = c(14, 19, 11, 0, 18), link_volume = c(500L, 
1550L, 350L, 100L, 550L), geometry = structure(list(structure(c(1065088.71736072, 
1065084.18813218, 1253892.13487564, 1253935.59094818), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(1060907.62521458, 
1060984.50834787, 1237578.71728528, 1237818.59111698), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(1063031.34624456, 
1062955.36965935, 1241210.04281066, 1241498.76584417), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(1063031.34624456, 
1063034.73081084, 1241210.04281066, 1241198.98905491), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg")), structure(c(1058112.52771678, 
1058131.02887377, 1236388.96345761, 1236342.13157851), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg"))), class = c("sfc_LINESTRING", 
"sfc"), precision = 0, bbox = structure(c(xmin = 1058112.52771678, 
ymin = 1236342.13157851, xmax = 1065088.71736072, ymax = 1253935.59094818
), class = "bbox"), crs = structure(list(epsg = 5070L, proj4string = "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"), class = "crs"), n_empty = 0L)), sf_column = "geometry", agr = structure(c(linkid = NA_integer_, 
departure_hour = NA_integer_, link_volume = NA_integer_), .Label = c("constant", 
"aggregate", "identity"), class = "factor"), row.names = c(NA, 
5L), class = c("sf", "data.table", "data.frame"))
dataanalyst
  • 316
  • 3
  • 12
  • for me removing the `exit_*()` call worked. No idea why though, maybe we should raise a bug with the gganimate team – Phil Dec 01 '20 at 19:44

0 Answers0