New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition fails when using geom_edge_link or geom_edge_arc #196

Open
timlrx opened this Issue Oct 13, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@timlrx
Copy link

timlrx commented Oct 13, 2018

library(tidygraph)
library(ggraph)
library(gganimate)
gr <- create_ring(5) 

p <- ggraph(gr) + 
  geom_edge_arc() + 
  geom_node_point() + 
  theme_graph() + 
  transition_manual(from)

animate(p)
#> Error in mapply(FUN = f, ..., SIMPLIFY = FALSE): zero-length inputs cannot be mixed with those of non-zero length

I tested with geom_edge_link and it gives the same error message. Strangely, geom_edge_link0 seems to work fine. This might be related to the transition fails for ggraph issue.

@ChuckFinley

This comment has been minimized.

Copy link

ChuckFinley commented Nov 7, 2018

I'm getting a similar error when combining transitions with maps. E.g.

p <- ggplot(wtsh_dummy) +
  geom_sf(data = area, fill = 'white') + 
  geom_point(aes(Longitude, Latitude, group = DeployID, color = DeployID), 
             size = 2.5) +
  transition_components(DeployID, TimestampUTC)
animate(p, 200, 10)

fails with Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length but

p <- ggplot(wtsh_dummy) +
  # geom_sf(data = area, fill = 'white') + 
  geom_point(aes(Longitude, Latitude, group = DeployID, color = DeployID), 
             size = 2.5) +
  transition_components(DeployID, TimestampUTC)
animate(p, 200, 10)

works.

@ChuckFinley

This comment has been minimized.

Copy link

ChuckFinley commented Nov 9, 2018

Here's a simple repo:

library(tidyverse)
library(gganimate)
library(sf)

# Create data
time <- seq(ISOdate(2015, 6, 1), ISOdate(2015, 8, 1), length.out = 100)
track1 <- tibble(lon = seq(-161, -155, length.out = 100),
                 lat = seq(19, 25, length.out = 100),
                 time = time,
                 trackid = 1)
track2 <- tibble(lon = seq(-155, -161, length.out = 100),
                 lat = seq(19, 25, length.out = 100),
                 time = time,
                 trackid = 2)
d <- rbind(track1, track2)

# Animating points works
p <- ggplot(d, aes(lon, lat)) +
  geom_point() +
  labs(subtitle = 'Date: {format(frame_time, "%b %e")}') +
  transition_components(trackid, time) +
  shadow_trail(distance = 0.01, size = 0.3)
animate(p, 100, 20)

# Create spatial data
earth <- st_as_sf(rnaturalearth::ne_download(scale = "medium",
                                             category = "physical",
                                             type = "coastline"))
deg_buff <- 1
lon_range <- range(d$lon) + c(-deg_buff, deg_buff)
lat_range <- range(d$lat) + c(-deg_buff, deg_buff)
bbox <- st_polygon(list(cbind(lon_range[c(1,1,2,2,1)], lat_range[c(1,2,2,1,1)])))
bbox <- st_sfc(bbox)
st_crs(bbox) <- st_crs(earth)
area <- st_intersection(earth, bbox)

# Creating a static map works
ggplot(d, aes(lon, lat)) +
  geom_sf(data = area, inherit.aes = FALSE) +
  geom_point()

# Animating the map fails
p2 <- ggplot(d, aes(lon, lat)) +
  geom_sf(data = area, inherit.aes = FALSE) +
  geom_point() +
  labs(subtitle = 'Date: {format(frame_time, "%b %e")}') +
  transition_components(trackid, time) +
  shadow_trail(distance = 0.01, size = 0.3)
animate(p2, 100, 20)
@dfsnow

This comment has been minimized.

Copy link

dfsnow commented Nov 17, 2018

I'm having the same issue with transition_components using more than one geom in the same plot. For example:

# Works fine
plot <- ggplot() +
  # geom_point(
  #   data = stops_df,
  #   aes(x = lon, y = lat, color = route_id),
  #   size = 3,
  #   show.legend = FALSE
  #   ) +
  geom_point(
    data = trips_df,
    aes(x = lon, y = lat),
    size = 2,
    shape = 15
    ) +
 transition_components(trip_id, time)

# Fails with the below error
plot <- ggplot() +
  geom_point(
     data = stops_df,
     aes(x = lon, y = lat, color = route_id),
     size = 3,
     show.legend = FALSE
     ) +
  geom_point(
    data = trips_df,
    aes(x = lon, y = lat),
    size = 2,
    shape = 15
    ) +
 transition_components(trip_id, time)

Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length

@ChuckFinley

This comment has been minimized.

Copy link

ChuckFinley commented Dec 19, 2018

Is this related? Two geoms using the same data with transition_components fails, but it's a different error message: Warning message: In split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) : NAs introduced by coercion

library(tidyverse)
t <- 1:100
x <- 1:100
y <- 1:100
df <- rbind(tibble(x = x, 
                   y = y,
                   t = t,
                   id = 1),
            tibble(x = rev(x),
                   y = y, 
                   t = t,
                   id = 2))
# One geom works
ggplot(df, aes(x, y)) +
  geom_point() +
  transition_components(id, t)
# Two geoms work with transition_time...
df2 <- tibble(x = 50, y = 50)
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_point(data = df2,
             size = 10) +
  transition_time(t)
# ...but fail with transition_components
ggplot(df, aes(x, y)) +
  geom_point() +
  geom_point(data = df2,
             size = 10) +
  transition_components(id, t)
@thomasp85

This comment has been minimized.

Copy link
Owner

thomasp85 commented Dec 19, 2018

They are not related... can I get you to open a new issue?

@ChuckFinley

This comment has been minimized.

Copy link

ChuckFinley commented Dec 19, 2018

Will do.

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