Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A tidy API for graph manipulation

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

thomasp85/tidygraph

Repository files navigation

R-CMD-checkCRAN_Release_BadgeCRAN_Download_BadgeCoverage Status

This package provides a tidy API for graph/network manipulation. Whilenetwork data itself is not tidy, it can be envisioned as two tidytables, one for node data and one for edge data.tidygraph provides away to switch between the two tables and providesdplyr verbs formanipulating them. Furthermore it provides access to a lot of graphalgorithms with return values that facilitate their use in a tidyworkflow.

An example

library(tidygraph)play_gnp(10,0.5) %>%   activate(nodes) %>%   mutate(degree= centrality_degree()) %>%   activate(edges) %>%   mutate(centrality= centrality_edge_betweenness()) %>%   arrange(centrality)#> # A tbl_graph: 10 nodes and 51 edges#> ##> # A directed simple graph with 1 component#> ##> # Edge Data: 51 × 3 (active)#>     from    to centrality#>    <int> <int>      <dbl>#>  1     2     7       1.25#>  2     6     5       1.33#>  3     1     3       1.4#>  4     2    10       1.53#>  5     2     8       1.58#>  6     8     9       1.65#>  7     2     3       1.67#>  8     2     5       1.73#>  9     3     5       1.73#> 10     8     5       1.73#> # ℹ 41 more rows#> ##> # Node Data: 10 × 1#>   degree#>    <dbl>#> 1      6#> 2      7#> 3      6#> # ℹ 7 more rows

Overview

tidygraph is a huge package that exports 280 different functions andmethods. It more or less wraps the full functionality ofigraph in atidy API giving you access to almost all of thedplyr verbs plus a fewmore, developed for use with relational data.

More verbs

tidygraph adds some extra verbs for specific use in network analysisand manipulation. Theactivate() function defines whether one ismanipulating node or edge data at the moment as shown in the exampleabove.bind_edges(),bind_nodes(), andbind_graphs() let youexpand the graph structure you’re working with, whilegraph_join()lets you merge two graphs on some node identifier.reroute(), on theother hand, lets you change the terminal nodes of the edges in thegraph.

More algorithms

tidygraph wraps almost all of the graph algorithms fromigraph andprovides a consistent interface and output that always matches thesequence of nodes and edges. Alltidygraph algorithm wrappers areintended for use inside verbs where they know the context they are beingcalled in. In the example above it is not necessary to supply the graphnor the node/edge IDs tocentrality_degree() andcentrality_edge_betweenness() as they are aware of them already. Thisleads to much clearer code and less typing.

More maps

tidygraph goes beyonddplyr and also implements graph centricversion of thepurrr map functions. You can now call a function on thenodes in the order of a breadth or depth first search while gettingaccess to the result of the previous calls.

More morphs

tidygraph lets you temporarily change the representation of yourgraph, do some manipulation of the node and edge data, and then changeback to the original graph with the changes being merged inautomatically. This is powered by the newmorph()/unmorph() verbsthat let you e.g. contract nodes, work on the linegraph representation,split communities to separate graphs etc. If you wish to continue withthe morphed version, thecrystallise() verb lets youfreeze thetemporary representation into a propertbl_graph.

More data structure support

Whiletidygraph is powered by igraph underneath it wants everyone tojoin the fun. Theas_tbl_graph() function can easily convertrelational data from all your favourite objects, such asnetwork,phylo,dendrogram,data.tree,graph, etc. More conversion willbe added in the order I become aware of them.

Visualisation

tidygraph itself does not provide any means of visualisation, but itworks flawlessly withggraph. This division makes it easy to developthe visualisation and manipulation code at different speeds depending onwhere the needs arise.

Installation

tidygraph is available on CRAN and can be installed simply, usinginstall.packages('tidygraph'). For the development version availableon GitHub, use thedevtools package for installation:

# install.packages('pak')pak::pak('thomasp85/tidygraph')

Thanks

tidygraph stands on the shoulders of particularly theigraph anddplyr/tidyverse teams. It would not have happened without them, sothanks so much to them.

Code of Conduct

Please note that the tidygraph project is released with aContributorCode ofConduct. Bycontributing to this project, you agree to abide by its terms.

About

A tidy API for graph manipulation

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors20

Languages


[8]ページ先頭

©2009-2025 Movatter.jp