The r toolbox grainscape for modelling and visualizing landscape connectivity using spatially explicit networks
Abstract
- Networks are widely used for modelling landscape connectivity and have many ecological and conservation applications. The nodes in these models describe geographic locations (such as habitat patches or protected areas) and links describe the potential for organisms (or their propagules) to move among nodes.
- We present the r package grainscape which facilitates working with these networks within a spatially explicit framework. Package analyses are based on the minimum planar graph, a class of network where links among nodes are influenced by the spatial characteristics of features across the entire landscape.
- Modelling outputs are compatible with downstream packages including igraph for network analysis and ggplot2 for visualization. Tools for analysis (e.g. finding corridors) and scaling networks (e.g. grains of connectivity) are also provided. Models can be exported for visualization and analysis in Geographic Information System (GIS) or network software.
- This package provides a computationally‐efficient programmatic toolbox for many landscape connectivity research questions, enabling researchers to easily customize models, work at large geographic extents, generate their own network metrics, conduct sensitivity analyses and seamlessly employ r statistical functions to test models using biological data. A detailed guide, provided as an Appendix, illustrates common analysis and model variants with accompanying r code.
1 INTRODUCTION
Studies of landscape connectivity ask the questions: how may organisms distribute themselves on the landscape? What limits or encourages this movement? And retrospectively: how has the landscape shaped the observed demographic and genetic structure of the populations? Landscape connectivity models have been used for a variety of purposes including: conservation planning, managing landscape change and habitat fragmentation, constructing corridors and protected area networks, understanding impediments to dispersal and gene flow, estimating the availability of ecosystem services to agriculture, helping wildlife populations adapt to climate change and, reducing risks associated with the spread of human diseases or invasive species (Albert, Rayfield, Dumitru, & Gonzalez, 2017; Auffret et al., 2017; Castillo et al., 2016; Lechner, Sprod, Carter, & Lefroy, 2017; McGuire, Lawler, McRae, Nuñez, & Theobald, 2016; Perry, Moloney, & Etherington, 2017; Rayfield, Pelletier, Dumitru, Cardille, & Gonzalez, 2016; Sahraoui, Foltête, & Clauzel, 2017; Saura et al., 2018; Sousa & Small, 2016; Travis Belote et al., 2016; Watts et al., 2018).
The resistance surface (Figure 1a) describes connectivity as its inverse, the resistance to movement (Zeller, McGarigal, & Whiteley, 2012), and represents landscape features as the factor by which they may slow (or resist) the movement of the organism or its propagules. Interpretation consists of measuring the connectivity between two locations on the surface using one of several metrics, among which least‐cost path and resistance distance are widely used (Adriaensen et al., 2003; McRae, Dickson, Keitt, & Shah, 2008).

A second class of functional connectivity model, the patch network (Figure 1b–e) characterizes connectivity relationships among resource patches (Galpern, Manseau, & Fall, 2011; Urban, Minor, Treml, & Schick, 2009). This type of model is preferred for organisms restricted to structurally discrete or isolated resource patches (i.e. grey regions; Figure 1b–e), such as amphibians in wetlands, arboreal mammals inhabiting forest fragments (e.g. Bodin & Norberg, 2006; Jeliazkov et al., 2019), or in protected area modelling (e.g. Hofman, Hayward, Kelly, & Balkenhol, 2018). These networks are often mapped, where patches are nodes, and potential paths for dispersal among patches are links (Figure 1b–e; Dale & Fortin, 2010; Fall, Fortin, Manseau, & O’Brien, 2007; Urban et al., 2009). They have also been combined with resistance surfaces to model the links patches (Figure 1b,c).
The grainscape package for r integrates features of both modelling traditions and facilitates a range of connectivity analyses using patch networks. The package gives researchers programmatic control over the construction and interpretation of patch network models, and provides tools for scaling, visualizing, and analysing connectivity. It is also the first publicly available package to provide a type of spatially explicit patch network called the minimum planar graph (hereafter MPG), a spatial representation of a mathematical graph or network that provides an efficient approximation of all possible pairwise connections between graph nodes (Fall et al., 2007). A unique feature of this approach is that the configuration of all patches influences the network structure. The ability to work with models in r facilitates parameter customization, sensitivity assessments, and seamless integration of statistical tests using biological data.
2 MODELLING WITH grainscape
The input to grainscape is a resistance surface raster map, and optionally a second raster indicating the focal patches that serve as nodes in a network. Landscape connectivity modelling begins with the MPG which has links that model the possibility for organism movement between spatially adjacent focal patches (Figure 1b–d). In some cases, neighbouring patches may not be linked, if the shortest path distance between them can be made through a third patch (e.g. Figure 1b; patches containing points P and Q are not directly connected). A description of the algorithm to extract the MPG is provided in Appendix S1.
In practice, the MPG can be used to easily visualize patch connectivity (Galpern et al., 2011). This planar graph, with relationships limited to neighbouring nodes, may be the most biologically relevant abstraction (i.e. nearer patches are likely more important destinations than those farther away). The alternative, the complete graph, linking all pairs of connected nodes, neighbouring and otherwise, becomes challenging to interpret because the density of links may obscure any pattern. A reduced set of links is also advantageous where computational efficiency is important, and essential when large numbers of patches are being modelled.
3 THRESHOLDING AND SCALING LANDSCAPE CONNECTIVITY
Patch networks have the useful property of being modifiable to represent an increasing potential for landscape connectivity (Urban et al., 2009). A behavioural parameter (typically the maximum amount of movement by an organism or its propagules) is used to create a map showing groups of connected and disconnected patches (compare Figure 1d,e). This is called thresholding, and a group of connected patches represents a single meta‐patch (i.e. a cluster, or in graph theory, a component).
Connectivity models should be parsimonious, representing how organisms are expected to respond to landscape heterogeneity that influences movement, and omitting any heterogeneity that should not (Cushman & Landguth, 2010; Galpern & Manseau, 2013a). A scaling approach related to thresholding, called grains of connectivity (GOC) can help achieve parsimony (Galpern, Manseau, & Wilson, 2012) and is also implemented in grainscape. GOC model the landscape as a network of continuous but irregular tessellations (Voronoi polygons; Fall et al., 2007), where tiles are like cells on a resistance surface but have much larger areas and variable shapes and sizes (Figure 1f,g). These describe regions of proximity in resistance units from the margins of each patch (e.g. patches in Figure 1e), or in lattice GOC, from an artificial grid of points superimposed on the map (Figure 1h). The GOC model resembles a resistance surface in that movement can be modelled to or from any location on the map (e.g. Figure 1g,h; points P and Q).
Scaling with GOC is done by thresholding the graph to create components, then combining the polygons containing patches to delineate a region of the landscape that is connected. As this region grows in size, the area influencing dispersal decreases in proportion (i.e. there are fewer links influencing movement). This can be used to let increases in the threshold coarsen the spatial grain of landscape data, simplifying it in a way that reflects a functional connectivity hypothesis. GOC has been described and validated using both genetic and wildlife telemetry data (Galpern & Manseau, 2013b; Galpern et al., 2012), and is also described in Appendix S2.
4 FEATURES OF grainscape
A detailed usage guide, accompanied by r code, is included in the package as a vignette (also as Appendix S2). The following section highlights several features of the package.
4.1 Network construction options
4.1.1 Node dimensionality
grainscape constructs networks using nodes representing patches as points or as two‐dimensional (2D) regions. Links can be found between 2D patch perimeters (Fall et al., 2007), a spatially explicit feature allowing the shape of the patch and its configuration with neighbours to influence the end points of the link (Figure 1b). Modelling 2D patches and link endpoints in a spatially explicit manner is a distinctive feature of grainscape.
4.1.2 Link weighting
grainscape produces networks where links represent paths between patch perimeters. The path between neighbouring patches depends on the values on the resistance surface and, for 2D nodes, the shape and configuration of the patches. The link between two patches may describe the shortest path between any two points on either patch perimeter (i.e. the path distance). However, as the path also depends on neighbouring patches, the modelled path may not always be the shortest one. Where Euclidean—rather than resistance—distance is preferred (e.g. for certain aquatic or airborne organisms), link weights can be found using a unit resistance surface (i.e. where all raster cells are equal to 1).
4.2 Thresholding and scaling options
4.2.1 Thresholding
grainscape can threshold the patch network by removing links from the MPG that are greater than or equal to a given path distance. This permits analysis under different assumptions about the maximum effective separation between patches that constitutes a connection. Multi‐threshold comparison provides a sensitivity analysis for connectivity when the maximum is not known.
4.2.2 Patch GOC
Patches can be used to supervise the polygon generation in a GOC model. This implies that the resource represented by the patch supports landscape connectivity (e.g. Figure 1f,g).
4.2.3 Lattice GOC
Analogous to patch GOC, lattice GOC uses a grid of points superimposed on the resistance surface that supervise generation of polygons (Figure 1h). This is an upscaling of the resistance surface unsupervised by patches, and may be appropriate for simplifying resistance surfaces where raster upscaling techniques (e.g. modal aggregation of neighbouring cells) eliminate small footprint features of high importance, such as roads or rivers (see Galpern and Manseau (2013a) for a comparative evaluation of this method).
4.3 Visualization and analysis options
The package provides plotting functionality with default settings suitable for quick visualizations of analysis outputs, using the ggplot2 package (Wickham, 2016). Furthermore, standard ggplot2 syntax can be used to customize node attributes and link weights (e.g. using colour, shape, style, or thickness), to plot networks and to represent links connecting the perimeters or the centroids of patches (compare Figure 1c,d).
Patch networks or GOC models can be exported for use in external geographic information system or network modelling software, or for cartographic applications. Both raster and vector data are exported in several widely recognized formats. Network objects are in igraph format (Csardi & Nepusz, 2006) and can be analysed using that package. Connectivity predictions can also be made using igraph (e.g. finding the shortest‐path and its accumulated path distance between a start and end point). This offers researchers flexibility to customize network analyses, quantify network properties and implement their own indices of connectivity (e.g. Pereira, Saura, & Jordán, 2017).Additionally, grainscape provides functions for analysing GOC models, including a corridor function for visualizing the shortest path between two locations (Figure 1g,h) and for finding pairwise corridor distances between a set of points, a technique that may be useful, for example, in landscape genetics.
5 LANDSCAPE CONNECTIVITY ANALYSIS WITH grainscape
To further illustrate the potential for application of grainscape to real‐world problems, we present a landscape connectivity analysis for an unspecified alpine species in the Canadian Rockies (Appendix S3).We demonstrate creation of a resistance surface, calculate the MPG, and analyse shortest path and corridor connectivity, which can be used to support regional assessments.
Applications of grainscape to single species will typically incorporate more biological information than provided in this simplified example. Data used to inform parameters may include organism fitness, survivorship or time spent in land covers, as well as dispersal behaviour or capacity (Galpern et al., 2011). For multiple species or for protected area connectivity, researchers may prefer to generalize as we have done, due to the absence of information, or alternatively, to simplify interpretation by decision‐making audiences. However, in all cases we recommend model‐building conclude with sensitivity analyses that vary parameters (e.g. resistance, threshold, scale) within meaningful bounds and report predictions that incorporate this uncertainty.
6 COMPUTING WITH grainscape
Models can be built quickly even under demanding research scenarios, enabling many parameterizations to be examined in a reasonable timeframe. The analytical engine behind grainscape is provided as a cross‐platform C++ implementation (see Appendix S1). It is able to handle input rasters of any size, and on a 64‐bit CPU is limited only by available RAM. For example, extraction of the MPG for a highly fragmented artificial landscape comparable in dimension to a Landsat scene (36 million cells; equivalent to a 180 × 180 km extent at 30 m resolution) finishes in about 11 min on a 2015 Intel Xeon CPU. Simulation experiments demonstrated that compute time increased quadratically with the number of patches and linearly with the number of cells, when the other variable was held constant (see Appendix S4).
7 INSTALLATION AND DEVELOPMENT VERSIONS
grainscape can be installed directly from CRAN. Development versions and source code are available on GitHub (https://github.com/achubaty/grainscape), where bug reports can be filed, and contributions can be made via pull request.
The software in these repositories represents a complete rewrite of an unpublished version previously available for download on R‐Forge. The new version shares a minimal codebase with the old and employs a redeveloped algorithm for extracting MPGs, now written in C++. It also adds new analysis and visualization features, is many times faster, has no software limitations on landscape size and eliminates reliance on a proprietary binary distribution of 32‐bit Windows‐only software.
ACKNOWLEDGEMENTS
This work was supported, in part, by funding from the Natural Sciences and Engineering Research Council.
AUTHORS' CONTRIBUTIONS
All authors contributed to writing the manuscript main text, the conceptual design of the package and the specification of the algorithm that supports network extraction. A.M.C. implemented the package from the r side. S.C.D. implemented the C++ engine for network extraction and was the primary author of Appendix S1. P.G. was the primary author of analysis, visualization and scaling functionality as well as Appendices S2–S4.
Open Research
DATA AVAILABILITY STATEMENT
The r package that is the subject of this paper is available on CRAN at https://CRAN.R-project.org/package=grainscape (Galpern, Doctolero, & Chubaty, 2019) and its external data folder includes the raster used to construct the examples in Figure 1. Both the manual distributed with the r package and the detailed tutorial in Appendix S2 contain the code necessary to reproduce analyses shown in Figure 1.




