Skip to content
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

Error tweening ggraph when using the start_cap/end_cap aes #263

Open
adamsma opened this issue Oct 28, 2020 · 0 comments
Open

Error tweening ggraph when using the start_cap/end_cap aes #263

adamsma opened this issue Oct 28, 2020 · 0 comments

Comments

@adamsma
Copy link

adamsma commented Oct 28, 2020

I wasn't sure if this should be posted under ggraph, tweenr, or maybe even gganimate. This issue stems from the geometry class in ggraph so I posted here. I figure since all three have the same (great) author and maintainer, it could be moved if it's more appropriate elsewhere.

In short when I try to animate a ggraph, it doesn't work if I use the start_cap and/or end_cap aesthetics. Here is an example:

library(tidygraph)
library(ggraph)
library(gganimate)
library(purrr)

baseG <-
  # create set of n-complete graphs to transition through
  seq(3,7) %>%
  map(
    ~create_complete(.x) %N>%
      mutate(group = .x) %E>%
      mutate(group = .x)
  ) %>%
  bind_graphs() %>%
  # build out common base to ggraph, gganim
  ggraph(layout = "kk") +
  geom_node_point(
    aes(color = group, size = 3),
    show.legend = FALSE
  ) +
  theme_void() +
  transition_states(group) + enter_fade() + exit_fade()

# adding edges successfully renders
animate(baseG + geom_edge_link())

# adding edges using aes with geometry class results in error
rlang::with_abort(
  animate(
    baseG + geom_edge_link(
      aes(start_cap = circle(3, "mm"), end_cap = circle(3, "mm"))
    )
  )
)

The error message from the final expression is Error: Only possible to insert geometries.

I dug into it a bit. Essentially what appears to be happening is the geometry columns gets mistaken for character columns in tweenr::tween_state. The data coming from ggraph has columns start_cap and end_cap which are of class geometry. The non-exported function col_classes returns their classes, and consequently the columns in tweendata, as character. When trying to rbind the tween data with to and from, the replacement function [<-.geometry is ultimately called and throws the error.

Ultimately, the error is generated by a call similar to

rbind(
  tibble::tibble(x = ggraph::rectangle()),
  tibble::tibble(x = letters[1:3])
)

but I would say the error stems from triggering the wrong interpolation.

I wouldn't consider this a major bug since it can still be animated without using the caps. It just looks, to use your word, "Ugh" especially when you add in arrows to the edges.

Also, thank you for all the work you do on these packages and the rest of the R visualization stack!

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

No branches or pull requests

2 participants