{"id":13857264,"url":"https://github.com/schochastics/edgebundle","last_synced_at":"2025-04-08T03:16:44.641Z","repository":{"id":41475372,"uuid":"321618760","full_name":"schochastics/edgebundle","owner":"schochastics","description":"R package implementing edge bundling algorithms","archived":false,"fork":false,"pushed_at":"2024-09-23T18:57:30.000Z","size":16686,"stargazers_count":129,"open_issues_count":2,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-04T23:42:28.997Z","etag":null,"topics":["graph-algorithms","network-analysis","rstats","visualization"],"latest_commit_sha":null,"homepage":"https://schochastics.github.io/edgebundle/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schochastics.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-15T09:33:47.000Z","updated_at":"2025-03-11T15:53:35.000Z","dependencies_parsed_at":"2023-01-29T21:46:42.329Z","dependency_job_id":"375aa1eb-419c-4bef-a496-0ca1648a91c4","html_url":"https://github.com/schochastics/edgebundle","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"f669b665ab6ece4ebd823faa5701860f756c3701"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fedgebundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fedgebundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fedgebundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schochastics%2Fedgebundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schochastics","download_url":"https://codeload.github.com/schochastics/edgebundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767236,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph-algorithms","network-analysis","rstats","visualization"],"created_at":"2024-08-05T03:01:31.938Z","updated_at":"2025-04-08T03:16:44.606Z","avatar_url":"https://github.com/schochastics.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n    collapse = TRUE,\n    comment = \"#\u003e\",\n    fig.path = \"man/figures/README-\",\n    out.width = \"100%\"\n)\nlibrary(edgebundle)\n```\n\n# edgebundle  \u003cimg src=\"man/figures/logo.png\" align=\"right\"/\u003e\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/schochastics/edgebundle/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/schochastics/edgebundle/actions/workflows/R-CMD-check.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/edgebundle)](https://CRAN.R-project.org/package=edgebundle)\n[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/edgebundle)](https://CRAN.R-project.org/package=edgebundle) \n\u003c!-- badges: end --\u003e\n\nAn R package that implements several edge bundling/flow and metro map algorithms. So far it includes\n\n- Force directed edge bundling \n- Stub bundling ([paper](https://www.uni-konstanz.de/mmsp/pubsys/publishedFiles/NoBr13.pdf))\n- Hammer bundling ([python code](https://datashader.org/_modules/datashader/bundling.html))\n- Edge-path bundling ([paper](https://arxiv.org/abs/2108.05467))\n- TNSS flow map ([paper](https://doi.org/10.1080/15230406.2018.1437359))\n- Multicriteria Metro map layout ([paper](https://doi.org/10.1109/TVCG.2010.24))\n\n**[ggraph 2.2.0](https://www.data-imaginist.com/posts/2024-02-15-ggraph-2-2-0/) supports edge bundling natively via `geom_edge_bundle_*()` functions. This means that parts of this package are now deprecated.**\n\n## Installation\n\nThe package is available on CRAN.\n\n```{r cran, eval=FALSE}\ninstall.packages(\"edgebundle\")\n```\n\nThe developer version can be installed with\n\n``` {r dev, eval=FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"schochastics/edgebundle\")\n```\n\nNote that `edgebundle` imports `reticulate` and uses a pretty big python library (datashader).\n\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n    collapse = TRUE,\n    comment = \"#\u003e\"\n)\n```\n\n```{r setup,warning=FALSE,message=FALSE}\nlibrary(edgebundle)\nlibrary(igraph)\n```\n\n## Edge bundling\n\nThe expected input of each edge bundling function is a graph (igraph/network or tbl_graph object) and a node layout.   \nAll functions return a data frame of points along the edges of the network that can be plotted with {{ggplot2}} using `geom_path()` or\n`geom_bezier()` for `edge_bundle_stub()`.\n```{r example,message=FALSE}\nlibrary(igraph)\ng \u003c- graph_from_edgelist(\n    matrix(c(1, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7), ncol = 2, byrow = T), F\n)\nxy \u003c- cbind(c(rep(0, 6), rep(1, 6)), c(1:6, 1:6))\n\nfbundle \u003c- edge_bundle_force(g, xy, compatibility_threshold = 0.1)\nhead(fbundle)\n```\n\nThe result can be visualized as follows.\n\n```{r plot,message=FALSE,fig.align='center'}\nlibrary(ggplot2)\n\nggplot(fbundle) +\n    geom_path(aes(x, y, group = group, col = as.factor(group)),\n        size = 2, show.legend = FALSE\n    ) +\n    geom_point(data = as.data.frame(xy), aes(V1, V2), size = 5) +\n    theme_void()\n\n# simple edge-path bundling example\ng \u003c- graph_from_edgelist(matrix(c(1, 2, 1, 6, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6),\n    ncol = 2, byrow = TRUE\n), FALSE)\nxy \u003c- cbind(c(0, 10, 25, 40, 50, 50), c(0, 15, 25, 15, 0, -10))\nres \u003c- edge_bundle_path(g, xy, max_distortion = 2, weight_fac = 2, segments = 50)\n\nggplot() +\n    geom_path(\n        data = res, aes(x, y, group = group, col = as.factor(group)),\n        size = 2, show.legend = FALSE\n    ) +\n    geom_point(data = as.data.frame(xy), aes(V1, V2), size = 5) +\n    scale_color_manual(values = c(\"grey66\", \"firebrick3\", \"firebrick3\", rep(\"grey66\", 4))) +\n    theme_void()\n```\n\nFor `edge_bundle_stub()`, you need `geom_bezier()` from the package {{ggforce}}.\n\n```{r bezier,message=FALSE,fig.align='center'}\nlibrary(ggforce)\ng \u003c- graph.star(10, \"undirected\")\n\nxy \u003c- matrix(c(\n    0, 0,\n    cos(90 * pi / 180), sin(90 * pi / 180),\n    cos(80 * pi / 180), sin(80 * pi / 180),\n    cos(70 * pi / 180), sin(70 * pi / 180),\n    cos(330 * pi / 180), sin(330 * pi / 180),\n    cos(320 * pi / 180), sin(320 * pi / 180),\n    cos(310 * pi / 180), sin(310 * pi / 180),\n    cos(210 * pi / 180), sin(210 * pi / 180),\n    cos(200 * pi / 180), sin(200 * pi / 180),\n    cos(190 * pi / 180), sin(190 * pi / 180)\n), ncol = 2, byrow = TRUE)\n\nsbundle \u003c- edge_bundle_stub(g, xy, beta = 90)\n\nggplot(sbundle) +\n    geom_bezier(aes(x, y, group = group), size = 1.5, col = \"grey66\") +\n    geom_point(data = as.data.frame(xy), aes(V1, V2), size = 5) +\n    theme_void()\n```\n\nThe typical edge bundling benchmark uses a dataset on us flights, which is included in the package.\n\n```{r example-code,eval = FALSE}\ng \u003c- us_flights\nxy \u003c- cbind(V(g)$longitude, V(g)$latitude)\nverts \u003c- data.frame(x = V(g)$longitude, y = V(g)$latitude)\n\nfbundle \u003c- edge_bundle_force(g, xy, compatibility_threshold = 0.6)\nsbundle \u003c- edge_bundle_stub(g, xy)\nhbundle \u003c- edge_bundle_hammer(g, xy, bw = 0.7, decay = 0.5)\npbundle \u003c- edge_bundle_path(g, xy, max_distortion = 12, weight_fac = 2, segments = 50)\n\nstates \u003c- map_data(\"state\")\n\n\np1 \u003c- ggplot() +\n    geom_polygon(\n        data = states, aes(long, lat, group = group),\n        col = \"white\", size = 0.1, fill = NA\n    ) +\n    geom_path(\n        data = fbundle, aes(x, y, group = group),\n        col = \"#9d0191\", size = 0.05\n    ) +\n    geom_path(\n        data = fbundle, aes(x, y, group = group),\n        col = \"white\", size = 0.005\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"#9d0191\", size = 0.25\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"white\", size = 0.25, alpha = 0.5\n    ) +\n    geom_point(\n        data = verts[verts$name != \"\", ],\n        aes(x, y), col = \"white\", size = 3, alpha = 1\n    ) +\n    labs(title = \"Force Directed Edge Bundling\") +\n    ggraph::theme_graph(background = \"black\") +\n    theme(plot.title = element_text(color = \"white\"))\n\np2 \u003c- ggplot() +\n    geom_polygon(\n        data = states, aes(long, lat, group = group),\n        col = \"white\", size = 0.1, fill = NA\n    ) +\n    geom_path(\n        data = hbundle, aes(x, y, group = group),\n        col = \"#9d0191\", size = 0.05\n    ) +\n    geom_path(\n        data = hbundle, aes(x, y, group = group),\n        col = \"white\", size = 0.005\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"#9d0191\", size = 0.25\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"white\", size = 0.25, alpha = 0.5\n    ) +\n    geom_point(\n        data = verts[verts$name != \"\", ], aes(x, y),\n        col = \"white\", size = 3, alpha = 1\n    ) +\n    labs(title = \"Hammer Edge Bundling\") +\n    ggraph::theme_graph(background = \"black\") +\n    theme(plot.title = element_text(color = \"white\"))\n\nalpha_fct \u003c- function(x, b = 0.01, p = 5, n = 20) {\n    (1 - b) * (2 / (n - 1))^p * abs(x - (n - 1) / 2)^p + b\n}\n\np3 \u003c- ggplot() +\n    geom_polygon(\n        data = states, aes(long, lat, group = group),\n        col = \"white\", size = 0.1, fill = NA\n    ) +\n    ggforce::geom_bezier(\n        data = sbundle, aes(x, y,\n            group = group,\n            alpha = alpha_fct(..index.. * 20)\n        ), n = 20,\n        col = \"#9d0191\", size = 0.1, show.legend = FALSE\n    ) +\n    ggforce::geom_bezier(\n        data = sbundle, aes(x, y,\n            group = group,\n            alpha = alpha_fct(..index.. * 20)\n        ), n = 20,\n        col = \"white\", size = 0.01, show.legend = FALSE\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"#9d0191\", size = 0.25\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"white\", size = 0.25, alpha = 0.5\n    ) +\n    geom_point(\n        data = verts[verts$name != \"\", ], aes(x, y),\n        col = \"white\", size = 3, alpha = 1\n    ) +\n    labs(title = \"Stub Edge Bundling\") +\n    ggraph::theme_graph(background = \"black\") +\n    theme(plot.title = element_text(color = \"white\"))\n\np4 \u003c- ggplot() +\n    geom_polygon(\n        data = states, aes(long, lat, group = group),\n        col = \"white\", size = 0.1, fill = NA\n    ) +\n    geom_path(\n        data = pbundle, aes(x, y, group = group),\n        col = \"#9d0191\", size = 0.05\n    ) +\n    geom_path(\n        data = pbundle, aes(x, y, group = group),\n        col = \"white\", size = 0.005\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"#9d0191\", size = 0.25\n    ) +\n    geom_point(\n        data = verts, aes(x, y),\n        col = \"white\", size = 0.25, alpha = 0.5\n    ) +\n    geom_point(\n        data = verts[verts$name != \"\", ], aes(x, y),\n        col = \"white\", size = 3, alpha = 1\n    ) +\n    labs(title = \"Edge-Path Bundling\") +\n    ggraph::theme_graph(background = \"black\") +\n    theme(plot.title = element_text(color = \"white\"))\n\np1\np2\np3\np4\n```\n\n```{r,fig.width=8,fig.height=6,fig.align='center',out.width=\"95%\",echo=FALSE}\nknitr::include_graphics(\"man/figures/flights_fdeb.png\")\nknitr::include_graphics(\"man/figures/flights_heb.png\")\nknitr::include_graphics(\"man/figures/flights_seb.png\")\nknitr::include_graphics(\"man/figures/flights_peb.png\")\n```\n\n\n## Flow maps\n\nA flow map is a type of thematic map that represent movements. It may thus be considered a hybrid of a map and a flow diagram.\nThe package so far implements a spatial one-to-many flow layout algorithm using\ntriangulation and approximate Steiner trees.\n\nThe function `tnss_tree()` expects a one-to-many flow network (i.e. a weighted star graph), a layout for the nodes and\na set of dummy nodes created with `tnss_dummies()`. \n\n```{r example_flow,eval=FALSE}\nlibrary(ggraph)\nxy \u003c- cbind(state.center$x, state.center$y)[!state.name %in% c(\"Alaska\", \"Hawaii\"), ]\nxy_dummy \u003c- tnss_dummies(xy, 4)\ngtree \u003c- tnss_tree(cali2010, xy, xy_dummy, 4, gamma = 0.9)\n\nggraph(gtree, \"manual\", x = V(gtree)$x, y = V(gtree)$y) +\n    geom_polygon(data = us, aes(long, lat, group = group), fill = \"#FDF8C7\", col = \"black\") +\n    geom_edge_link(aes(width = flow, col = sqrt((xy[root, 1] - ..x..)^2 + (xy[root, 2] - ..y..)^2)),\n        lineend = \"round\", show.legend = FALSE\n    ) +\n    scale_edge_width(range = c(0.5, 4), trans = \"sqrt\") +\n    scale_edge_color_gradient(low = \"#cc0000\", high = \"#0000cc\") +\n    geom_node_point(aes(filter = tnss == \"leaf\"), size = 1) +\n    geom_node_point(aes(filter = (name == \"California\")), size = 5, shape = 22, fill = \"#cc0000\") +\n    theme_graph() +\n    labs(title = \"Migration from California (2010) - Flow map\")\n```\n\n```{r,fig.width=8,fig.height=6,fig.align='center',out.width=\"95%\",echo=FALSE}\nknitr::include_graphics(\"man/figures/cali2010_flow.png\")\n```\n\nTo smooth the tree, use `tnss_smooth()`. Note that this changes the object type and\nyou need to visualize it with {{ggplot2}} rather than {{ggraph}}.\n\n```{r example_flow_smooth,eval=FALSE}\nsmooth_df \u003c- tnss_smooth(gtree, bw = 5, n = 20)\n\nggplot() +\n    geom_polygon(data = us, aes(long, lat, group = group), fill = \"#FDF8C7\", col = \"black\") +\n    geom_path(\n        data = smooth_df, aes(x, y, group = destination, size = flow),\n        lineend = \"round\", col = \"firebrick3\", alpha = 1\n    ) +\n    theme_void() +\n    scale_size(range = c(0.5, 3), guide = \"none\") +\n    labs(title = \"Migration from California (2010) - Flow map smoothed\")\n```\n\n```{r,fig.width=8,fig.height=6,fig.align='center',out.width=\"95%\",echo=FALSE}\nknitr::include_graphics(\"man/figures/cali2010_flow_smoothed.png\")\n```\n\nSee [this gallery](http://minard.schochastics.net/) for more examples and code.\n\n## Metro Maps\n\nMetro map(-like) graph drawing follow certain rules, such as octilinear edges. The algorithm\nimplemented in the packages uses hill-climbing to optimize several features desired in a metro map.\nThe package includes the metro map of Berlin as an example.\n\n```{r metro_example, eval = FALSE}\n# the algorithm has problems with parallel edges\ng \u003c- simplify(metro_berlin)\nxy \u003c- cbind(V(g)$lon, V(g)$lat) * 100\n\n# the algorithm is not very stable. try playing with the parameters\nxy_new \u003c- metro_multicriteria(g, xy, l = 2, gr = 0.5, w = c(100, 100, 1, 1, 100), bsize = 35)\n\n# geographic layout\nggraph(metro_berlin, \"manual\", x = xy[, 1], y = xy[, 2]) +\n    geom_edge_link0(aes(col = route_I_counts), edge_width = 2, show.legend = FALSE) +\n    geom_node_point(shape = 21, col = \"white\", fill = \"black\", size = 3, stroke = 0.5)\n\n# schematic layout\nggraph(metro_berlin, \"manual\", x = xy_new[, 1], y = xy_new[, 2]) +\n    geom_edge_link0(aes(col = route_I_counts), edge_width = 2, show.legend = FALSE) +\n    geom_node_point(shape = 21, col = \"white\", fill = \"black\", size = 3, stroke = 0.5) +\n    theme_graph() +\n    labs(title = \"Subway Network Berlin\")\n```\n\n```{r,fig.width=8,fig.height=6,fig.align='center',out.width=\"95%\",echo=FALSE}\nknitr::include_graphics(\"man/figures/metro_berlin.png\")\n```\n\n## Disclaimer\n\nEdge bundling is able to produce neat looking network visualizations. However, they do not \nnecessarily enhance readability. After experimenting with several methods, it became quite\nevident that the algorithms are very sensitive to the parameter settings (and often really only work in the showcase examples...). Consult the original literature (if they even provide any guidelines) or experiment yourself and **do not expect any miracles**.\n\n","funding_links":[],"categories":["R","Software","Data and models"],"sub_categories":["R"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschochastics%2Fedgebundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschochastics%2Fedgebundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschochastics%2Fedgebundle/lists"}