Skip to contents

Species-habitat associations in R provides a toolset of functions in the R programming language to analyze species-habitat associations. Therefore, information about the location of the species (as a point pattern) and the environmental conditions (as a raster) is needed. In order to analyse the data for significant habitat associations either the location data or the environmental data is randomized n-times. Then, counts within the habitats are compared between the observed and the randomized data. Positive or negative associations are present if the observed counts are higher or lower than the randomized counts (using quantile thresholds). Methods are described in Plotkin et al. (2000), Harms et al. (2001) and Wiegand & Moloney (2014). shar is mainly based on the spatstat (Baddeley et al. 2015) and terra (Hijmans 2022) package.

You can find more information and help using the corresponding homepage.


You can install the released version of shar from CRAN with:

And the development version from GitHub with:

# install.packages("remotes")

This also automatically installs all non-base R package dependencies, namely: classInt, spatstat.explore, spatstat.geom, spatstat.model, spatstat.random, and terra.

How to use shar

Please refer to vignette("Get started") and the homepage to get an introduction to shar.


The shar package is part of our academic work. To cite the package or acknowledge its use in publications, please cite the following paper.

Hesselbarth, M.H.K., (2021). shar: A R package to analyze species-habitat associations using point pattern analysis. Journal of Open Source Software, 6(67), 3811.

The get a BibTex entry, please use citation("shar").

Contributing and Code of Conduct

Contributions to shar are highly welcomed and appreciated. This includes any form of feedback, bug reports, feature requests/suggestions, or general questions about the usage.

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

To contribute to this project, please see the Contributing guidelines.