Skip to content

Commit

Permalink
version 0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ladylavender authored and cran-robot committed Feb 7, 2024
0 parents commit 92d4cec
Show file tree
Hide file tree
Showing 29 changed files with 1,819 additions and 0 deletions.
38 changes: 38 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,38 @@
Package: LandComp
Title: Analysing Landscape Composition and Structure at Multiple Scales
Version: 0.0.5
Authors@R: c(
person(given = c("Krisztina", "Dóra"), family = "Konrád", email = "konrad.krisztina@ecolres.hu", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-4414-8766")),
person(given = "Ákos", family = "Bede-Fazekas", role = c("aut", "ths", "cph"), comment = c(ORCID = "0000-0002-2905-338X")),
person(given = "Sándor", family = "Bartha", role = c("cph"), comment = c(ORCID = "0000-0001-6331-7521")),
person(given = "Imelda", family = "Somodi", role = c("ccp", "ths", "cph"), comment = c(ORCID = "0000-0002-6207-3796")))
Description: Changes of landscape diversity and structure can be detected
soon if relying on landscape class combinations and analysing patterns
at multiple scales. 'LandComp' provides such an opportunity, based on
Juhász-Nagy's functions (Juhász-Nagy P, Podani J 1983
<doi:10.1007/BF00129432>). Functions can handle multilayered data.
Requirements of the input: binary data contained by a regular square
or hexagonal grid, and the grid should have projected coordinates.
License: MIT + file LICENSE
Suggests: knitr, rmarkdown, testthat
Encoding: UTF-8
Language: En
RoxygenNote: 7.3.0
Imports: future, future.apply, sf
Depends: R (>= 2.10)
LazyData: true
VignetteBuilder: knitr
URL: https://github.com/ladylavender/LandComp,
https://ladylavender.github.io/LandComp/
BugReports: https://github.com/ladylavender/LandComp/issues
NeedsCompilation: no
Packaged: 2024-02-05 19:05:20 UTC; Kriszti
Author: Krisztina Dóra Konrád [aut, cre, cph]
(<https://orcid.org/0000-0002-4414-8766>),
Ákos Bede-Fazekas [aut, ths, cph]
(<https://orcid.org/0000-0002-2905-338X>),
Sándor Bartha [cph] (<https://orcid.org/0000-0001-6331-7521>),
Imelda Somodi [ccp, ths, cph] (<https://orcid.org/0000-0002-6207-3796>)
Maintainer: Krisztina Dóra Konrád <konrad.krisztina@ecolres.hu>
Repository: CRAN
Date/Publication: 2024-02-06 17:30:08 UTC
2 changes: 2 additions & 0 deletions LICENSE
@@ -0,0 +1,2 @@
YEAR: 2024
COPYRIGHT HOLDER: LandComp authors
28 changes: 28 additions & 0 deletions MD5
@@ -0,0 +1,28 @@
c255bed33243656a6e1301e58d62f75f *DESCRIPTION
bc0d0acbf6942744201d2de53dd34143 *LICENSE
2a52ee3282aa991369d7ea320622764e *NAMESPACE
61bd55ad94656d9625684e9e90420368 *NEWS.md
4ff2514670eede75569ceb60f02d6be1 *R/LandComp.R
ea7cde865e2f3703be2e810b497fb3be *R/calculate_SpatialUnitSize.R
943adabcf4851d1ba2b6b435f4c030e9 *R/data.R
6bb4e7e14cdd2914a81d67dc4e021976 *README.md
d760edd7966e017bd7433e453cd57c61 *build/vignette.rds
bd7456fd574f11b720db29192ab502f4 *data/hexagonal_data.rda
20fb8bb07599682e56f6f199aa65b075 *data/square_data.rda
35337293cab43b450fea64d1c72a7cf5 *inst/CITATION
990e6ebfadbef9bb84af23f950ba9eb2 *inst/doc/LandComp.R
3587a5886b64768d470eab08dc543162 *inst/doc/LandComp.Rmd
1396685d9e34c23d01691cd98a09fda8 *inst/doc/LandComp.html
fed3ad40d9e49b7360f33ee0dd35ce35 *man/LandComp.Rd
ba12b31f9137f12344081b03fcbb8916 *man/calculate_SpatialUnitSize.Rd
ae527504750a5b012d271f88283fd5d2 *man/figures/README-hexagonal_data-1.png
39732d475b78f2c588af1804e8736449 *man/figures/README-square_data-1.png
81df5e3d2836fe9ec7bcdd4da78cc6e6 *man/figures/logo.png
24d9f0b0826e151545c624599ef52c72 *man/figures/spatial_units_hexagon.png
b1c0383134f2ba26d50bfa247e03ec2c *man/figures/spatial_units_square.png
96bcb623f263d449ecea5d586745cc19 *man/hexagonal_data.Rd
2c882e0f5c2abaa29131c5b902d03c5c *man/square_data.Rd
bb0b5bdd9cde2b15cfc0ca9eac1b742d *tests/testthat.R
806bb3bc5d5c20127e4aeeeac0bed374 *tests/testthat/test-LandComp.R
76840dd75eed1afcd43058e6da76e167 *tests/testthat/test-calculate_SpatialUnitSize.R
3587a5886b64768d470eab08dc543162 *vignettes/LandComp.Rmd
4 changes: 4 additions & 0 deletions NAMESPACE
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(LandComp)
export(calculate_SpatialUnitSize)
16 changes: 16 additions & 0 deletions NEWS.md
@@ -0,0 +1,16 @@
# LandComp 0.0.5

* Updated 'Description' file.
* The package became compatible with CRAN.

# LandComp 0.0.4

# LandComp 0.0.3

* Updated 'Description' file.

# LandComp 0.0.2

# LandComp 0.0.1

* Initial CRAN submission.
319 changes: 319 additions & 0 deletions R/LandComp.R

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions R/calculate_SpatialUnitSize.R
@@ -0,0 +1,68 @@
#'Number of grid cells covered by enlarged spatial units
#'
#'Calculate the number of grid cells covered by the radially enlarged spatial
#'units.
#'
#'@param aggregation_step A numeric vector of length one containing a
#' non-negative number. This number expresses the size of the spatial units for
#' which calculation of compositional diversity and associatum is required. The
#' size is measured by the number of rows of grid cells around the central grid
#' cell, where 0 means the original cell without enlargement. Fraction number
#' can be also set as input. In this case, the following step's spatial unit
#' minus grid cells touching the vertices are used as spatial base units. Note,
#' in the case of hexagonal grid, steps falling in the interval ]0,1[ cannot be
#' evaluated. Negative, non-finite and missing values are ignored with warning.
#'@param square A logical vector of length one. Should be `TRUE` if square grid,
#' `FALSE`, if is hexagonal grid is used as the basis of calculation.
#'
#'@return A numeric vector of length one.
#'@export
#'
#'@examples
#' calculate_SpatialUnitSize(aggregation_step = 0, square = TRUE)
#'
#' foo = c()
#' for(i in c(0, 0.5, 1, 1.5, 2, 3))
#' foo = c(foo, calculate_SpatialUnitSize(aggregation_step = i, square = TRUE))
#' foo
#'
#' vapply(c(0, 1, 1.5, 2, 3), FUN = function(i){
#' calculate_SpatialUnitSize(aggregation_step = i, square = FALSE)},
#' FUN.VALUE = numeric(length = 1))
#'
calculate_SpatialUnitSize = function(aggregation_step, square = FALSE){
# Checking parameters
if(missing(aggregation_step)) stop("Parameter 'aggregation_step' should be set.")
if(any(is.na(aggregation_step))){
aggregation_step = aggregation_step[!is.na(aggregation_step)]
warning("NA values provided to parameter 'aggregation_step' are ignored.")
}
if(any(!is.finite(aggregation_step))){
aggregation_step = aggregation_step[is.finite(aggregation_step)]
warning("Infinite values provided to parameter 'aggregation_step' are ignored.")
}
if(length(aggregation_step)>1){
warning("Parameter 'aggregation_step' has more elements (", as.character(length(aggregation_step)), ") then expected (1). Only the first element is used.")
aggregation_step <- aggregation_step[1]
} else if(length(aggregation_step)<1) stop("Parameter 'aggregation_step' should be of length one.")
if(aggregation_step < 0) stop("Parameter 'aggregation_step' should be non-negative.")
if(!is.numeric(aggregation_step)) stop("Parameter 'aggregation_step' should be a numeric.")
if(length(square)>1){
warning("Parameter 'square' has more elements (", as.character(length(square)), ") then expected (1). Only the first element is used.")
square <- square[1]
} else if(length(square)<1) stop("Parameter 'square' should be of length one.")
if(!is.logical(square)) stop("Parameter 'square' should be logical.")
if(is.na(square)) stop("NA values provided to parameter 'square'.")
if(aggregation_step >0 & aggregation_step <1 & !square) stop("Value (", aggregation_step,") set to parameter 'aggregation_steps' falling in the range ]0,1[ cannot be evaluated when using hexagonal grid.")

# Calculation
aggregation_step_is_integer = aggregation_step %% 1 == 0
if(square){ # square grid
count <- (ceiling(aggregation_step)*2+1)^2 # formula to use if the given aggregation_step is integer
if(!aggregation_step_is_integer) count <- count - 4 # formula to use if the given aggregation_step is fraction
}else{ # hexagonal grid
count <- sum((0:ceiling(aggregation_step)) * 6) + 1 # formula to use if the given aggregation_step is integer
if(!aggregation_step_is_integer) count <- count - 6 # formula to use if the given aggregation_step is fraction
}
count
}
23 changes: 23 additions & 0 deletions R/data.R
@@ -0,0 +1,23 @@
#' Sample vegetation data with hexagonal grid
#'
#' A generated dataset containing presences and absences of five vegetation types.
#'
#' @docType data
#' @name hexagonal_data
#' @usage data(hexagonal_data)
#' @format An `sf` object with 300 rows and 6 variables.
#' @author Krisztina Dóra Konrád \email{konrad.krisztina@@ecolres.hu}
"hexagonal_data"


#' Sample vegetation data with square grid
#'
#' A generated dataset containing presences and absences of five vegetation types.
#'
#'
#' @docType data
#' @name square_data
#' @usage data(square_data)
#' @format An `sf` object with 300 rows and 6 variables.
#' @author Krisztina Dóra Konrád \email{konrad.krisztina@@ecolres.hu}
"square_data"
125 changes: 125 additions & 0 deletions README.md
@@ -0,0 +1,125 @@

<!-- Readme document of LandComp R package -->
<!-- badges: start -->

[![R-CMD-check](https://github.com/ladylavender/LandComp/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ladylavender/LandComp/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

# LandComp

A package that enables quantifying landscape diversity and structure at
multiple scales. For these purposes Juhász-Nagy’s functions,
i.e. compositional diversity (CD) and associatum (AS), are calculated.

## Installation

You can install the development version of `LandComp` using the
following command:

``` r
install.packages("devtools")
devtools::install_github("ladylavender/LandComp")
```

## Example

Example regular grids represent demonstrative spatial arrangements. They
reflect a typical case when having presence/absence data on some
landscape classes (e.g. vegetation types here) along a landscape. Note,
there are three requirements of using the `LandComp` package:

- the landscape data should be numeric binary, i.e. it should contain 0
or 1 values
- the geometry of the landscape data should be a regular square or
hexagonal grid
- the geometry of the landscape data should have projected coordinates
(i.e. WGS84 is not eligible)

### Regular square grid data

The structure and the visualization of the example square grid data:

``` r
suppressPackageStartupMessages(library("sf"))
library(LandComp)
data("square_data")
plot(square_data)
```

![](man/figures/README-square_data-1.png)<!-- -->

``` r
str(square_data)
#> Classes 'sf' and 'data.frame': 300 obs. of 6 variables:
#> $ VT1 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ VT2 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ VT3 : num 0 0 0 0 1 1 0 0 0 0 ...
#> $ VT4 : num 0 0 0 0 0 0 0 1 1 1 ...
#> $ VT5 : num 0 0 0 0 0 0 0 0 0 1 ...
#> $ geometry:sfc_POLYGON of length 300; first list element: List of 1
#> ..$ : num [1:5, 1:2] 400000 400000 405000 405000 400000 ...
#> ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
#> - attr(*, "sf_column")= chr "geometry"
#> - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
#> ..- attr(*, "names")= chr [1:5] "VT1" "VT2" "VT3" "VT4" ...
```

Two values of CD and AS measuring landscape diversity and structure can
be calculated as e.g.

``` r
LandComp(x = square_data, aggregation_steps = 0:1)
#> AggregationStep SpatialUnit_Size SpatialUnit_Area SpatialUnit_Count
#> 1 0 1 2.50e+07 300
#> 2 1 9 2.25e+08 234
#> UniqueCombination_Count CD_bit AS_bit
#> 1 13 2.755349 0.1709469
#> 2 18 3.176364 1.0874836
```

### Regular hexagonal grid data

The structure and the visualization of the example hexagonal grid data:

``` r
data("hexagonal_data")
plot(hexagonal_data)
```

![](man/figures/README-hexagonal_data-1.png)<!-- -->

``` r
str(hexagonal_data)
#> Classes 'sf' and 'data.frame': 300 obs. of 6 variables:
#> $ VT1 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ VT2 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ VT3 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ VT4 : num 1 1 0 1 1 1 0 1 1 1 ...
#> $ VT5 : num 0 0 1 1 0 0 1 0 0 1 ...
#> $ geometry:sfc_POLYGON of length 300; first list element: List of 1
#> ..$ : num [1:7, 1:2] 649500 649000 649000 649500 650000 ...
#> ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
#> - attr(*, "sf_column")= chr "geometry"
#> - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
#> ..- attr(*, "names")= chr [1:5] "VT1" "VT2" "VT3" "VT4" ...
```

``` r
LandComp(x = hexagonal_data, aggregation_steps = 0:1)
#> AggregationStep SpatialUnit_Size SpatialUnit_Area SpatialUnit_Count
#> 1 0 1 866025.4 300
#> 2 1 7 6062177.8 234
#> UniqueCombination_Count CD_bit AS_bit
#> 1 12 1.972863 0.1256525
#> 2 16 3.422409 0.5394512
```

For further information and examples, see both the vignette of the
package and `?LandComp` after installing the package.
Note, if you would like to view the vignette from R using the code
`vignette("LandComp")`, you should install the package using the
following command:

``` r
devtools::install_github("ladylavender/LandComp", build_vignettes = TRUE)
```
Binary file added build/vignette.rds
Binary file not shown.
Binary file added data/hexagonal_data.rda
Binary file not shown.
Binary file added data/square_data.rda
Binary file not shown.
16 changes: 16 additions & 0 deletions inst/CITATION
@@ -0,0 +1,16 @@

bibentry(
bibtype = "Article",
header = "To cite LandComp in publications use:",
textVersion = paste("Konrád KD, Bede-Fazekas Á, Bartha S, Somodi I (2023) Adapting a multiscale approach to assess the compositional diversity of landscapes. Landscape Ecology 38:2731–2747. https://doi.org/10.1007/s10980-023-01759-y"),
title = "Adapting a multiscale approach to assess the compositional diversity of landscapes",
author = c(person(given = c("Krisztina", "Dóra"), family = "KONRÁD", role = "cph"),
person(given = "Ákos", family = "BEDE-FAZEKAS", role = "cph"),
person(given = "Sándor", family = "BARTHA", role = "cph"),
person(given = "Imelda", family = "SOMODI", role = "cph")),
journal = "Landscape Ecology",
year = "2023",
volume = "38",
pages = "2731–2747",
url = "https://doi.org/10.1007/s10980-023-01759-y"
)
43 changes: 43 additions & 0 deletions inst/doc/LandComp.R
@@ -0,0 +1,43 @@
## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(LandComp)

## ----square_data, echo = TRUE-------------------------------------------------
suppressPackageStartupMessages(library("sf"))
library(LandComp)
data("square_data")
str(square_data)

## ----square_data_plot, out.width = '100%', echo = FALSE-----------------------
knitr::include_graphics(path = "../man/figures/README-square_data-1.png")

## ----square_example1, echo=TRUE-----------------------------------------------
LandComp(x = square_data, aggregation_steps = 0)

## ----square_units_plot, out.width = '50%', echo = FALSE-----------------------
knitr::include_graphics(path = "../man/figures/spatial_units_square.png")

## ----square_example2, echo=TRUE-----------------------------------------------
LandComp(x = square_data, aggregation_steps = c(0.5, 1))

## ----hexagonal_data, echo = TRUE----------------------------------------------
data("hexagonal_data")
str(hexagonal_data)

## ----hexagonal_data_plot, out.width = '100%', echo = FALSE--------------------
knitr::include_graphics(path = "../man/figures/README-hexagonal_data-1.png")

## ----hexagonal_example1, echo=TRUE--------------------------------------------
LandComp(x = hexagonal_data, aggregation_steps = 0)

## ----hexagonal_units_plot, out.width = '50%', echo = FALSE--------------------
knitr::include_graphics(path = "../man/figures/spatial_units_hexagon.png")

## ----hexagonal_example2, echo=TRUE--------------------------------------------
LandComp(x = hexagonal_data, aggregation_steps = c(1, 1.5))

0 comments on commit 92d4cec

Please sign in to comment.