Coder Social home page Coder Social logo

ggraph's Introduction

ggraph

/dʒiː.dʒɪˈrɑːf/ (or g-giraffe)

Travis-CI Build Status AppVeyor Build Status CRAN_Release_Badge CRAN_Download_Badge

A grammar of graphics for relational data

ggraph is an extension of ggplot2 aimed at supporting relational data structures such as networks, graphs, and trees. While it builds upon the foundation of ggplot2 and its API it comes with its own self-contained set of geoms, facets, etc., as well as adding the concept of layouts to the grammar.

An example

library(ggraph)
#> Loading required package: ggplot2
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter

# Create graph of highschool friendships
graph <- as_tbl_graph(highschool) %>% 
    mutate(Popularity = centrality_degree(mode = 'in'))

# plot using ggraph
ggraph(graph, layout = 'kk') + 
    geom_edge_fan(aes(alpha = ..index..), show.legend = FALSE) + 
    geom_node_point(aes(size = Popularity)) + 
    facet_edges(~year) + 
    theme_graph(foreground = 'steelblue', fg_text_colour = 'white')

The core concepts

ggraph builds upon three core concepts that are quite easy to understand:

  1. The Layout defines how nodes are placed on the plot, that is, it is a conversion of the relational structure into an x and y value for each node in the graph. ggraph has access to all layout functions avaiable in igraph and furthermore provides a large selection of its own, such as hive plots, treemaps, and circle packing.
  2. The Nodes are the connected enteties in the relational structure. These can be plotted using the geom_node_*() family of geoms. Some node geoms make more sense for certain layouts, e.g. geom_node_tile() for treemaps and icicle plots, while others are more general purpose, e.g. geom_node_point().
  3. The Edges are the connections between the enteties in the relational structure. These can be visualized using the geom_edge_*() family of geoms that contain a lot of different edge types for different scenarios. Sometimes the edges are implied by the layout (e.g. with treemaps) and need not be plottet, but often some sort of line is warranted.

All of the tree concepts has been discussed in detail in dedicated blog posts that are also available as vignettes in the package. Please refer to these for more information.

Note: The linked blog posts are based on ggraph v1. After ggraph v1.1 the underlying implementation was moved to tidygraph and cleaned up, but this resulted in some breaking changes in the process. Therefore the vignette versions are generally recommended as they have been updated.

Supported data types

There are many different ways to store and work with relational data in R. ggraph is build upon tidygraph and the large swath of data structures it supports are thus natively supported in ggraph. In order to get a data type supported by ggraph, simply provide an as_tbl_graph method for it.

Installation

ggraph is available through CRAN and can be installed with install_packages('ggraph'). The package is under active development though and the latest set of features can be obtained by installing from this repository using devtools

devtools::install_github('thomasp85/ggraph')

Related work

ggraph is not the only package to provide some sort of support for relational data in ggplot2, though I'm fairly certain that it is the most ambituous. ggdendro provides support for dendrogram and hclust objects through conversion of the structures into line segments that can then be plotted with geom_segment(). ggtree provides more extensive support for all things tree-related, though it lacks some of the layouts and edge types that ggraph offers (it has other features that ggraph lacks though). For more standard hairball network plots ggnetwork, geomnet, and GGally all provide some functionality though none of them are as extensive in scope as ggraph.

ggraph's People

Contributors

charliejhadley avatar floresfdev avatar klmr avatar malcolmbarrett avatar ruaridhw avatar sumedh10 avatar thomasp85 avatar zkamvar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.