Skip to content

Commit

Permalink
add details compute fun and modify plot by depth fun
Browse files Browse the repository at this point in the history
  • Loading branch information
MatGreco90 committed Sep 13, 2024
1 parent 1b577cf commit 143ec13
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
11 changes: 7 additions & 4 deletions R/compute_concentrations.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Compute count conversions
#'
#' @description
#' __ADD DESCRIPTION__
#' Functions to convert species counts between different formats: raw abundance,
#' relative abundance, and number concentration, using counts metadata.
#'
#' @param data a `data.frame`. One obtained by `read_*_data()` functions.
#'
Expand All @@ -13,9 +14,11 @@
#'
#' @details
#'
#' - `compute_concentrations()` __ADD A FEW WORDS__
#' - `compute_frequencies()` __ADD A FEW WORDS__
#' - `compute_abundances()` __ADD A FEW WORDS__
#' - `compute_concentrations()` converts all counts to number concentrations (n specimens/m³).
#'
#' - `compute_frequencies()` converts all counts to relative abundances (% specimens per sampling unit).
#'
#' - `compute_abundances()` converts all counts to raw abundances (n specimens/sampling unit).
#'
#' @name computations
NULL
Expand Down
23 changes: 16 additions & 7 deletions R/plot_record_by_depth.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ plot_record_by_depth <- function(data) {

data <- data %>%
select(.data$sample_id, .data$sample_min_depth, .data$sample_max_depth) %>%
unite('sampling_interval', c(.data$sample_min_depth,
.data$sample_max_depth), sep = '-',
remove = TRUE) %>%
mutate(sampling_interval = ifelse(
.data$sample_min_depth == 0 | (.data$sample_min_depth <= 100 & .data$sample_max_depth <= 100),
'Surface - 100m',
ifelse(.data$sample_min_depth >= 100 & .data$sample_max_depth <= 300, '100m-300m',
ifelse(.data$sample_min_depth >= 300 & .data$sample_max_depth <= 500, '300m-500m',
ifelse(.data$sample_min_depth >= 500, 'Below 500m', 'Unknown'))))) %>%
select(-c(.data$sample_min_depth, .data$sample_max_depth)) %>%
distinct() %>%
group_by(.data$sampling_interval) %>%
count() %>%
ungroup() %>%
mutate(upper_lim = as.numeric(gsub("-.*", "", .data$sampling_interval)))
ungroup()

data$"sampling_interval" <- factor(data$"sampling_interval",
levels = c('Unknown',
'Below 500m',
'300m-500m',
'100m-300m',
'Surface - 100m'))

ggplot(data,
aes(stats::reorder(.data$sampling_interval, -.data$upper_lim),
.data$n)) +
aes(.data$sampling_interval, .data$n)) +
geom_col(width = 0.7, col = "black") +
xlab("Sampling interval") +
ylab("Number of FORCIS samples") +
Expand Down
9 changes: 5 additions & 4 deletions man/computations.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vignettes/data-visualization.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ plot_record_by_season(net_data)

## `plot_record_by_depth()`

The function `plot_record_by_depth()` plots the number of records (x-axis) by depth (y-axis).
The function `plot_record_by_depth()` plots the number of records (x-axis) by depth intervals (y-axis).


```{r 'plot-record-by-depth', eval=FALSE}
```{r 'plot-record-by-depth'}
# Plot number of records by depth ----
plot_record_by_depth(net_data)
```

0 comments on commit 143ec13

Please sign in to comment.