para_explo_abund: Exploratory plots of parasite abundance distributions

View source: R/para_explo_abund.R

para_explo_abundR Documentation

Exploratory plots of parasite abundance distributions

Description

Generates exploratory visualizations of parasite abundance distributions across taxa and optional grouping variables. The function produces histograms combined with kernel density curves to facilitate the assessment of distributional patterns, including skewness, dispersion and zero inflation.

Usage

para_explo_abund(dataset, sp_cols, group_vars = NULL,
 bins = 30, n_col = NULL, verbose = FALSE)

Arguments

dataset

Data frame containing parasite data.

sp_cols

Vector with the names of the columns containing parasite abundance (taxa) to be plotted.

group_vars

Vector with the names of categorical variables used to define groups (e.g., "Sex", "Site"). Default = NULL.

bins

Integer specifying the number of bins used in the histogram. Higher values provide finer resolution but may introduce noise, while lower values produce smoother but less detailed distributions. Default = 30.

n_col

Integer specifying the number of columns in the faceted plot layout. If NULL, the number of columns is determined automatically by ggplot2.Default = NULL.

verbose

A logical value indicating if progress messages should be given. Default = FALSE.

Details

The function reshapes the input dataset into a long format, where parasite taxa are treated as a single variable and their abundances as observations. For each parasite taxon and combination of grouping variables (if provided), the function generates:

  • A histogram representing the distribution of parasite abundance values

  • A kernel density curve (when sufficient data are available), providing a smoothed approximation of the underlying distribution.

Both elements are scaled to represent density, allowing direct comparison between distributions. These plots are intended for exploratory purposes and should not be used as formal inference tools. Faceting is applied to display each taxon and grouping combination in separate panels. Special cases are handled as follows:

  • When all abundance values for a given combination are zero, no histogram or density curve is drawn and a message is displayed indicating that the parasite was not recorded for that combination.

  • When the number of observations is insufficient (less than 2), a message is displayed indicating that there is not enough data to compute a meaningful distribution.

  • Density curves are only computed when there are more than two observations and non-zero variation.

All plots use independent scales (free scales) to better represent the variability within each facet.

Value

A ggplot2 object containing the generated faceted plots. This object can be further customized using standard ggplot2 functions.

Author(s)

Juan Manuel Cabrera, Exequiel Furlan and Elisa Helman

Examples


#Species 1 and 2

para_explo_abund (para_data$dataset,
                 sp_cols = c("Sp1", "Sp2"),
                 group_vars = c("Site", "Sp_host"),
                 bins = 30,
                 n_col = 4,
                 verbose = TRUE)

#Species 3 and 4

para_explo_abund (para_data$dataset,
                 sp_cols = c("Sp3", "Sp4"),
                 group_vars = c("Site", "Sp_host"),
                 bins = 30,
                 n_col = 4,
                 verbose = TRUE)


parasiteR documentation built on May 13, 2026, 9:08 a.m.