Closed loreabad6 closed 9 months ago
Nice integration (profane point of view), i'm new to sfnetwork and ggraph too, but searching a convenient way to plot sfnetwork object bring me to your blog post and then here. Hope Thomas will accept this PR. Nice work.
So sorry for the massive delay on coming back to this @loreabad6 โ are you still interested in getting this worked in? If so I'll have time to prioritise it now
Hi @thomasp85, I have not looked at it in years but will be happy if wwe can make it work. I'll take a look again at the current state and check if there are any other problems besides the ones I explained or if something needs to be updated from my implementation. Thanks for the time!
Well, thank you. Sorry it took so long ๐
Hi again @thomasp85, and no worries at all! I checked my fork and synced to the latest ggraph. I unfortunately don't know yet how to figure the ggproto issue, but I will create the PR and maybe you can help me figure it out? I would really appreciate it!
Thank you for the help! Happy to see this implemented ๐ Ping @luukvdmeer @RobinLovelace @agila5
By coincidence I've just been using {sfnetworks}
+ {tidygraph}
to group edges. Currently I'm doing the following:
grouped_net = net |>
sfnetworks::as_sfnetwork(directed = FALSE) |>
morph(to_linegraph) |>
mutate(group = group_edge_betweenness(n_groups = 4)) |>
unmorph() |>
activate(edges) |>
sf::st_as_sf() |>
select(group) |>
sf::st_transform("EPSG:4326")
plot(grouped_net, lwd = 3)
sf::st_write(grouped_net, "example_cohesive.geojson", delete_dsn = TRUE)
Resulting in this with minimal example dataset
Probably not the best place for it, could put in an {sfnetwork}
discussion, but wanted to flag that things seem to be working, although most {tidygraph}
grouping functions seem to work only on nodes...
Congratulations @loreabad6 and @thomasp85 ๐ ๐ ๐ I don't understand all the details, but you did a great job and the integration of ggraph
and sfnetworks
will be very useful for my research.
Update on this: I'm hitting a bug when trying to install the dev version to test this new functionality.
remotes::install_dev("ggraph")
Resulting in this:
installing to /home/robin/R/x86_64-pc-linux-gnu-library/4.3/00LOCK-ggraph/00new/ggraph/libs
** R
** data
*** moving datasets to lazyload DB
** byte-compile and prepare package for lazy loading
Error in eval(`_inherit`, env, NULL) : object 'GuideLegend' not found
Error: unable to load R code in package โggraphโ
Execution halted
ERROR: lazy loading failed for package โggraphโ
* removing โ/home/robin/R/x86_64-pc-linux-gnu-library/4.3/ggraphโ
Warning message:
In i.p(...) :
installation of package โ/tmp/Rtmpk6D8oL/file7ca1a673b8393/ggraph_2.1.0.9000.tar.gzโ had non-zero exit status
You'll need the dev version of ggplot2
Aha makes sense. Thanks!
Works great, thanks guys!
From the docs on #357
ggraph(largest_component_92, 'sf') +
geom_node_sf() +
geom_edge_sf(aes(colour = Quietness)) +
theme_void()
Hi Thomas, Lorena here from the
sfnetworks
package. As we talked about during the hackathon back in June I have been trying to implement support forsfnetworks
withggraph
.As a recap,
sfnetworks
bridgestidygraph
andsf
, generating objects of classsfnetwork
which are accepted both forsf
andtidygraph
functions. It subclassestbl_graph
and hence already possible to use withggraph
. However, support to create a ggraph that corresponds tosf
s geographical space is missing.I have been trying to implement support for this within my own forked branch. I now have:
sf layout
, which will place the nodes in their geographical space.geom_node_sf()
function which relies onGeomSf
to graph the nodes.geom_node_point()
, thegeom_node_sf()
option includes the CoordSf automatically with no need to callcoord_sf(crs)
.geom_edge_sf()
function which also indirecly relies onGeomSf
through aGeomEdgeSf
ggproto.edge_*
Ignoring unknown parameters
ggproto
objects and have a bit of difficulty following the workflow from the othergeom_edge_*()
functions available.facet_*()
gives problems sometimes.Here is what I have so far, the changes can be compared here.
I also tweaked
tbl_graph.R
to supportsfnetwork
objects.These are examples of how it works currently:
But when trying to pass aesthetics from variables, the rendering works good but the legend does not recognize the aesthetic names.
And sometimes facetting fails:
I would like to open a PR when these issues are fixed, but so far I think I am approaching the GeomEdgeSf wrong. I would really appreciate some help, not at all urgent. Also, considering that I am unsure how to handle
sfnetworks
andsf
in the Namespace yet and the checks keep failing. Thank you for your time!