Convert the number of observations for each species or non-species to proportion or percent cover within each row based on the total number of observations in each row. Useful for quadrats with varying numbers of observations to calculate each row's percent cover all at once.
Arguments
- data
A data frame with each row representing a sampling unit (ex. a quadrat or photo).
- spp
The column names containing all observations to be used in the proportion calculation. It is important to note that the proportions will be scaled to the total observations in these columns for each quadrat.
- prop
If
prop = TRUE
, the resulting cover will be proportions. Ifprop = FALSE
, the resulting cover will be in percentages.- total
If
total = TRUE
, a column containing the total number of observations at each sampling unit will be returned in a new column calledtotal_pts
. This will not be returned iftotal = FALSE
.
Examples
#create data set for example
Sites <- as.factor(c("One", "One", "Two", "Two", "Three", "Three"))
Transect <- as.factor(c("1-Shallow", "2-Shallow", "1-Shallow", "2-Shallow",
"1-Shallow", "2-Shallow"))
Acropora.sp <- c(1, 2, 3, 4, 5, 6)
Gardineroseris.sp <- c(6, 1, 2, 3, 4, 5)
Psammocora.sp <- c(5, 6, 1, 2, 3, 4)
Leptastrea.sp <- c(4, 5, 6, 1, 2, 3)
coral_cover <- data.frame(Sites, Transect, Acropora.sp, Gardineroseris.sp,
Psammocora.sp, Leptastrea.sp)
cover_calc(data = coral_cover, spp = names(coral_cover[3:6]), prop = TRUE, total = TRUE)
#> Sites Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1 One 1-Shallow 0.0625000 0.37500000 0.31250000 0.2500000
#> 2 One 2-Shallow 0.1428571 0.07142857 0.42857143 0.3571429
#> 3 Two 1-Shallow 0.2500000 0.16666667 0.08333333 0.5000000
#> 4 Two 2-Shallow 0.4000000 0.30000000 0.20000000 0.1000000
#> 5 Three 1-Shallow 0.3571429 0.28571429 0.21428571 0.1428571
#> 6 Three 2-Shallow 0.3333333 0.27777778 0.22222222 0.1666667
#> total_pts
#> 1 16
#> 2 14
#> 3 12
#> 4 10
#> 5 14
#> 6 18
cover_calc(data = coral_cover, spp = names(coral_cover[3:6]), prop = FALSE, total = FALSE)
#> Sites Transect Acropora.sp Gardineroseris.sp Psammocora.sp Leptastrea.sp
#> 1 One 1-Shallow 6.25000 37.500000 31.250000 25.00000
#> 2 One 2-Shallow 14.28571 7.142857 42.857143 35.71429
#> 3 Two 1-Shallow 25.00000 16.666667 8.333333 50.00000
#> 4 Two 2-Shallow 40.00000 30.000000 20.000000 10.00000
#> 5 Three 1-Shallow 35.71429 28.571429 21.428571 14.28571
#> 6 Three 2-Shallow 33.33333 27.777778 22.222222 16.66667