thomasp85 / ggraph

Grammar of Graph Graphics

Home Page:https://ggraph.data-imaginist.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filters resulting in empty data frames throw unexpected error in ggforce 0.3.4

rcannood opened this issue · comments

ggforce 0.3.4 seems to break a plotting function in dyngen. Note that I might implement a workaround in dyngen to avoid the package being removed from CRAN.

Edit: the example below now works because I implemented the workaround. See below for a smaller example that still errors.

Original example

Example:

install.packages("ggforce") # install ggforce 0.3.4
library(dyngen)
data("example_model")
plot_backbone_modulenet(example_model)
# Error in `check_required_aesthetics()`:
#   ! stat_edge_loop requires the following missing aesthetics: x, y, from, to, span, direction and strength
# Run `rlang::last_error()` to see where the error occurred.

When I install ggforce 0.3.3, the error is gone:

devtools::install_url("https://cran.r-project.org/src/contrib/Archive/ggforce/ggforce_0.3.3.tar.gz")
library(dyngen)
data("example_model")
plot_backbone_modulenet(example_model)
---

I managed to trim down the example. It appears the issue arises when the specified filter removes all of the rows from the data frame.

For example:

library(tidyverse)
library(ggraph)

nodes <- tribble(
  ~name,
  "A"
)
edges <- tribble(
  ~from, ~to, ~effect,
  "A", "A", 1
)
gr <- tidygraph::tbl_graph(nodes = nodes, edges = edges)
layout <- tribble(
  ~rowname, ~x, ~y,
  "A", 0, 0
) %>%
  as.data.frame() %>% 
  column_to_rownames()

# this works
ggraph(gr, layout = "manual", x = layout$x, y = layout$y) +
  geom_edge_loop(aes(filter = effect >= 0))

# this errors
ggraph(gr, layout = "manual", x = layout$x, y = layout$y) +
  geom_edge_loop(aes(filter = effect >= 0)) +
  geom_edge_loop(aes(filter = effect < 0))

I seem to be having a related issue in ggdag, also on a timeline for being removed (also working on a workaround!)

Can I get you to test it with the devel version of ggforce? I can't reproduce it right now (there has been a lot of upkeep so can't say what might have fixed the issue)

just tried it with the dev version of ggforce and got the following error with the code above

Error in `check_required_aesthetics()`:
! stat_edge_loop requires the following missing aesthetics: x, y, from, to, span, direction and strength
Run `rlang::last_error()` to see where the error occurred.

oh yeah - I just ran the first example that seems to now work... I can reproduce the second example error

Indeed, I implemented a workaround for the original example. I updated the post to reflect this. It's a pity that the dev version of ggforce didn't magically solve the issue ;)

It's an issue in ggraph not ggforce. Will be fixed soon

🙇 Thanks!

Should work now with dev ggforce and dev graph (soon to be released both of them)... sorry about that I have no idea why it worked before 😬

Thanks a lot Thomas! I appreciate your efforts in finding and solving the problem so quickly.