• Stars
    star
    529
  • Rank 80,477 (Top 2 %)
  • Language
    R
  • License
    Other
  • Created about 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tidy API for graph manipulation

tidygraph

R-CMD-check CRAN_Release_Badge CRAN_Download_Badge Coverage Status

This package provides a tidy API for graph/network manipulation. While network data itself is not tidy, it can be envisioned as two tidy tables, one for node data and one for edge data. tidygraph provides a way to switch between the two tables and provides dplyr verbs for manipulating them. Furthermore it provides access to a lot of graph algorithms with return values that facilitate their use in a tidy workflow.

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 and methods. It more or less wraps the full functionality of igraph in a tidy API giving you access to almost all of the dplyr verbs plus a few more, developed for use with relational data.

More verbs

tidygraph adds some extra verbs for specific use in network analysis and manipulation. The activate() function defines whether one is manipulating node or edge data at the moment as shown in the example above. bind_edges(), bind_nodes(), and bind_graphs() let you expand the graph structure you’re working with, while graph_join() lets you merge two graphs on some node identifier. reroute(), on the other hand, lets you change the terminal nodes of the edges in the graph.

More algorithms

tidygraph wraps almost all of the graph algorithms from igraph and provides a consistent interface and output that always matches the sequence of nodes and edges. All tidygraph algorithm wrappers are intended for use inside verbs where they know the context they are being called in. In the example above it is not necessary to supply the graph nor the node/edge IDs to centrality_degree() and centrality_edge_betweenness() as they are aware of them already. This leads to much clearer code and less typing.

More maps

tidygraph goes beyond dplyr and also implements graph centric version of the purrr map functions. You can now call a function on the nodes in the order of a breadth or depth first search while getting access to the result of the previous calls.

More morphs

tidygraph lets you temporarily change the representation of your graph, do some manipulation of the node and edge data, and then change back to the original graph with the changes being merged in automatically. This is powered by the new morph()/unmorph() verbs that let you e.g. contract nodes, work on the linegraph representation, split communities to separate graphs etc. If you wish to continue with the morphed version, the crystallise() verb lets you freeze the temporary representation into a proper tbl_graph.

More data structure support

While tidygraph is powered by igraph underneath it wants everyone to join the fun. The as_tbl_graph() function can easily convert relational data from all your favourite objects, such as network, phylo, dendrogram, data.tree, graph, etc. More conversion will be added in the order I become aware of them.

Visualisation

tidygraph itself does not provide any means of visualisation, but it works flawlessly with ggraph. This division makes it easy to develop the visualisation and manipulation code at different speeds depending on where the needs arise.

Installation

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

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

Thanks

tidygraph stands on the shoulders of particularly the igraph and dplyr/tidyverse teams. It would not have happened without them, so thanks so much to them.

Code of Conduct

Please note that the tidygraph project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

More Repositories

1

patchwork

The Composer of ggplots
R
2,354
star
2

gganimate

A Grammar of Animated Graphics
R
1,920
star
3

ggraph

Grammar of Graph Graphics
R
1,032
star
4

ggforce

Accelerating ggplot2
R
898
star
5

ggplot2_workshop

Material for "Drawing Anything with ggplot2" workshop
481
star
6

lime

Local Interpretable Model-Agnostic Explanations (R port of original Python package)
R
478
star
7

scico

Palettes for R based on the Scientific Colour-Maps
R
401
star
8

tweenr

Interpolate your data
R
395
star
9

fiery

A flexible and lightweight web server
R
239
star
10

shinyFiles

A shiny extension for server side file access
JavaScript
188
star
11

ggfx

Filters and Shaders for 'ggplot2'
R
161
star
12

densityClust

Clustering by fast search and find of density peaks
R
149
star
13

particles

A particle simulation engine based on a port of d3-force
R
118
star
14

transformr

Smooth Polygon Transformations
R
116
star
15

farver

High Performance Colourspace Manipulation in R
R
112
star
16

ambient

A Generator of Multidimensional Noise
R
91
star
17

euclid

Exact Computation Geometry Framework Based on 'CGAL'
C++
82
star
18

hierarchicalSets

Scalable Set Visualization using Hierarchies
R
54
star
19

Hr

Easy Access to Uppercase H
R
53
star
20

routr

Routing of Web Requests in R
R
53
star
21

reqres

Powerful classes for http requests and responses
R
36
star
22

curry

Partial Function Application with %<%, %-<%, and %><%
R
30
star
23

FindMyFriends

Fast alignment-free pangenome creation and exploration
R
27
star
24

pipeplotter

Syntactic ggplot2 Sugar for a Tidy World
R
26
star
25

fawkes

An R Interface to the AxiDraw plotter
R
25
star
26

pearls

Operations on Lists of Data Frames
R
18
star
27

ink

The Modern, High-Performant, Graphic Device for R
C++
17
star
28

PanVizGenerator

Create your own PanViz visualizations
R
17
star
29

ggplot2_mechanics

The Mechanics of ggplot2
TeX
16
star
30

plotting_benchmark

Investigating R graphics performance
HTML
16
star
31

grid

personal devel version of grid
R
15
star
32

PanViz

D3 based visualisation for comparative genomics
JavaScript
14
star
33

boundaries

Algorithms for Working With and Modifying Polygon Boundaries
C++
13
star
34

data_imaginist

data_imaginist source
HTML
12
star
35

nanodev

Graphic Devices for R based on NanoVG
C
10
star
36

MSGFgui

A gui overlay and extension for MSGFplus
R
10
star
37

orion

Spatial Searching for Euclid
C++
9
star
38

web_dev_in_R

Web Development for R Users
TeX
9
star
39

heroku-fiery-demo

A demo fiery application for deployment on Heroku
R
8
star
40

marquee

Markdown Parser and Renderer for R Graphics
C
8
star
41

unmeshy

A Vector Based 3D Renderer
C++
7
star
42

MSsary

Mass spectrometry data in R
R
7
star
43

RcppSNAP

'Rcpp' Integration for the SNAP Network Library
C++
6
star
44

tidy_graph_analysis

Tidy Network Analysis in R
TeX
6
star
45

polyclid

Polygon Support for Euclid
C++
6
star
46

mzID

An mzIdentML parser for R
R
6
star
47

MSGFplus

An MSGF+ interface for R
R
6
star
48

thomasp85.github.io

The source for data-imaginist.com
HTML
6
star
49

mvpcran

CRAN on a stick
R
5
star
50

shady

Compile and Execute Shaders from R
C++
5
star
51

anomaly

Detecting those outliers
R
4
star
52

d3Disco

A showcase for Shiny and D3 integration
JavaScript
4
star
53

firedock

Dockerfiles for fiery
R
4
star
54

phd_dissertation

Pangenome Tools for Rapid, Large-Scale Analysis of Bacterial Genomes
TeX
4
star
55

pepmaps

R package for quantitative peptidomics
R
2
star
56

masochist

For some reason I’m doing all of this from my phone
R
2
star
57

firedock_test

R
1
star
58

firesafety

Security for fiery apps
1
star
59

Biotools

Scripts for CMG-Biotools
Perl
1
star
60

circosScripts

Perl scripts to automate circos plots
Perl
1
star
61

CHtools

A list of diverse functions for CH
R
1
star