-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add support for nodes and edges in geographical space #357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really good. I have made a bunch of suggestions but most are cosmetic
As for your list of things, I've addressed 1) in my suggestions, 2) is unknown to me - do you have some examples of failures and I'll be happy to look into them, and 3) is also handled in the suggestions I think. |
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Thank you for the suggestions, I have incorporated them. Following up on the list:
ggraph(net, 'sf') +
geom_node_sf(aes(color = central)) +
geom_edge_sf(color = 'grey')
#> Warning in layer_sf(geom = GeomEdgeSf, data = data, mapping = mapping, stat = StatFilterSf, :
#> Ignoring unknown parameters: `colour` ### Need to write edge_* to get parameter
ggraph(net, 'sf') +
geom_node_sf(aes(color = central)) +
geom_edge_sf(edge_color = 'grey') |
And an example of a failed facetting case for point 2: library(sfnetworks)
library(tidygraph)
library(ggraph)
net = roxel %>%
as_sfnetwork() %>%
mutate(centrality = centrality_betweenness()) %>%
mutate(central = ifelse(centrality > 1000, T, F)) %>%
activate('edges') %>%
mutate(azimuth = edge_azimuth(), length = edge_length())
ggraph(net, 'sf') +
geom_node_sf(color = 'red', size = 0.05) +
geom_edge_sf(aes(color = type)) +
facet_graph(type ~ central)
#> Warning: Unknown or uninitialised column: `.ggraph.index`.
#> Error in `x[i, , drop = drop]`:
#> ! Can't subset rows with `i`.
#> ✖ Logical subscript `i` must be size 1 or 701, not 0.
#> Backtrace:
#> ▆
#> 1. ├─base::tryCatch(...)
#> 2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 3. │ ├─base (local) tryCatchOne(...)
#> 4. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 5. │ └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#> 6. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. ├─base::withCallingHandlers(...)
#> 9. ├─base::saveRDS(...)
#> 10. ├─base::do.call(...)
#> 11. ├─base (local) `<fn>`(...)
#> 12. ├─global `<fn>`(input = base::quote("cheap-stoat_reprex.R"))
#> 13. │ └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
#> 14. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
#> 15. │ └─knitr:::process_file(text, output)
#> 16. │ ├─knitr:::handle_error(...)
#> 17. │ │ └─base::withCallingHandlers(...)
#> 18. │ ├─base::withCallingHandlers(...)
#> 19. │ ├─knitr:::process_group(group)
#> 20. │ └─knitr:::process_group.block(group)
#> 21. │ └─knitr:::call_block(x)
#> 22. │ └─knitr:::block_exec(params)
#> 23. │ └─knitr:::eng_r(options)
#> 24. │ ├─knitr:::in_input_dir(...)
#> 25. │ │ └─knitr:::in_dir(input_dir(), expr)
#> 26. │ └─knitr (local) evaluate(...)
#> 27. │ └─evaluate::evaluate(...)
#> 28. │ └─evaluate:::evaluate_call(...)
#> 29. │ ├─evaluate (local) handle(...)
#> 30. │ │ └─base::try(f, silent = TRUE)
#> 31. │ │ └─base::tryCatch(...)
#> 32. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 33. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 34. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 35. │ ├─base::withCallingHandlers(...)
#> 36. │ ├─base::withVisible(value_fun(ev$value, ev$visible))
#> 37. │ └─knitr (local) value_fun(ev$value, ev$visible)
#> 38. │ └─knitr (local) fun(x, options = options)
#> 39. │ ├─base::withVisible(knit_print(x, ...))
#> 40. │ ├─knitr::knit_print(x, ...)
#> 41. │ └─knitr:::knit_print.default(x, ...)
#> 42. │ └─evaluate (local) normal_print(x)
#> 43. │ ├─base::print(x)
#> 44. │ └─ggplot2:::print.ggplot(x)
#> 45. │ ├─ggplot2::ggplot_build(x)
#> 46. │ ├─ggraph:::ggplot_build.ggraph(x)
#> 47. │ ├─base::NextMethod() at ggraph/R/ggraph.R:149:3
#> 48. │ └─ggplot2:::ggplot_build.ggplot(x)
#> 49. │ └─layout$setup(data, plot$data, plot$plot_env)
#> 50. │ └─ggplot2 (local) setup(..., self = self)
#> 51. │ └─base::lapply(...)
#> 52. │ └─ggplot2 (local) FUN(X[[i]], ...)
#> 53. │ └─ggraph (local) map_data(...)
#> 54. │ └─base::lapply(...) at ggraph/R/facet_graph.R:157:9
#> 55. │ └─ggraph (local) FUN(X[[i]], ...)
#> 56. │ ├─data[data$.ggraph.index %in% nodes, , drop = FALSE] at ggraph/R/facet_graph.R:158:11
#> 57. │ └─sf:::`[.sf`(data, data$.ggraph.index %in% nodes, , drop = FALSE) at ggraph/R/facet_graph.R:158:11
#> 58. │ ├─x[i, , drop = drop]
#> 59. │ └─tibble:::`[.tbl_df`(x, i, , drop = drop)
#> 60. │ └─tibble:::vectbl_as_row_index(i, x, i_arg)
#> 61. │ └─tibble:::vectbl_as_row_location(i, nr, i_arg, assign, call)
#> 62. │ ├─tibble:::subclass_row_index_errors(...)
#> 63. │ │ └─base::withCallingHandlers(...)
#> 64. │ └─vctrs::vec_as_location(...)
#> 65. └─vctrs (local) `<fn>`()
#> 66. └─vctrs:::stop_indicator_size(...)
#> 67. └─rlang::cnd_signal(...) |
The edge param thing was an oversight when I made the last batch of suggestions. Let me have a look at the facet thing |
So, it seems everything works if |
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
So I realized the main reason to include it is that when creating a ggraph only with sf nodes the projection of the data is lost, so there is distorsion since the nodes just adapt to the panel area. Maybe it could be handled with coord_sf? I will try to experiment |
Yeah, I can see the CRS are not picked up with the basic layout as nodes |
Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Thank you very much for reviewing this @thomasp85, I tested again and seems like all the issues I raised work now. |
Great - can I get you to add a NEWS bullet as well |
Done! |
Thank you!!! |
See #275 for details. Main issues for now are:
sfnetworks
andsf
in the NAMESPACE