Skip to main content
Dryad logo

comspat: an R package to analyze within-community spatial organization using species combinations


Tsakalos, James et al. (2022), comspat: an R package to analyze within-community spatial organization using species combinations, Dryad, Dataset,


The diversity of species combinations observable in sampling units reflects a species’ uneven distribution and preference for specific abiotic and biotic conditions – a phenomenon most commonly expressed in terms of ecological assembly rules of plant communities and other sessile organisms (e.g., subtidal algae, invertebrates and coral reefs). We present comspat, a new R package that uses grid or transect data sets to measure the number of realized (observed) species combinations (NRC) and the Shannon diversity of realized species combinations (compositional diversity; CD) as a function of spatial scale. NRC and CD represent two measures from a model family developed by Pál Juhász-Nagy based on Information Theory. Classical Shannon diversity measures biodiversity based on the number and relative abundance of species, whereas the specific version of Shannon diversity presented here characterizes biodiversity and provides information on species coexistence relationships; both measures operate at fine-scale within the sampling unit or within the community. comspat offers two commonly applied null models, complete spatial randomness and random shift, to disentangle the textural, intraspecific, and interspecific effects on the observed spatial patterns. Combined, these models assist users in detecting and interpreting spatial associations and inferring assembly mechanisms. Our open-sourced package provides a vignette that describes the method and reproduces the figures from this paper to help users contextualize and apply functions to their data.


We introduce comspat, which calculates the number of realized species combinations (NRC) and diversity of species combinations (called compositional diversity; CD) as a function of the sampling scale. comspat provides two main functions: one to calculate results (‘comspat’) and one to assist in their interpretation (‘comspat_plot’). The package includes five data sets to demonstrate its operation; we used three in-text (see Tsakalos et al. 2022) and present the remaining in the vignette.

Data included in the manuscript

The manuscript used three grid data sets (64 × 64 sampling units), including: one simulation (grid_patchy_associated) and two simulation derivatives (grid_random and grid_patchy_no_isc) produced by randomization. We used a spatially explicit individual-based simulation model (PATPRO) to create the grid_patchy_associated data set; this simulation represents a realistic grid community pattern featuring interspecific species associations and environmental responses (Bartha et al. 1998, Czaran, 1993). RS and CSR randomizations of the original simulation (grid_patchy_associated) produced the grid_n_isc and grid_random data sets. The grid_n_isc data set maintains species-level patterns; however, the interspecific relationships are randomized. The grid_random data set shows random species distribution, no intraspecific autocorrelations and no interspecific spatial associations. For additional details, please see the package vignette.

Data not included in the manuscript, but included in the package at the time of submission

The package contains two transects with real data sampled in open sand grassland in Hungary (Bartha et al. 2008). These real transect data sets were from Bartha et al.'s (2008) long-term study on the effect of climate change on the interannual variability of grassland communities. The transect data sets represent: (1) the spatial pattern data of frequent species (species with more than 25 presences along the transect) selected as a threshold from standard textbooks; tran_grass_s), and (2) the spatial pattern data of plant functional types (PFT; in this case data of species which belong to the same functional groups were merged; tran_grass_t). These data represent the same transect and same community; however, when merging species, all rare species were also considered within the PFT. For simplicity, we have only selected a 25 m example with a very typical pattern; this extent (transect length) is already representative of the community pattern.


Tsakalos, J. L. et al. 2022. comspat: an R package to analyze within-community spatial organization using species combinations. – Ecography, doi: 10.1111/ecog.06216

Bartha, S. et al. 2008. Will interannual variability in sand grassland communities increase with climate change?. –Community Ecol., 9: 13–21.

Usage Notes

The most recent version of the comspat package can be accessed from github's public repository ( The authors also plan to submit the package to The Comprehensive R Archive Network.