para_explo_prev: Exploratory plots of parasite prevalence

View source: R/para_explo_prev.R

para_explo_prevR Documentation

Exploratory plots of parasite prevalence

Description

Generates exploratory visualizations of parasite prevalence across taxa and optional grouping variables. The function produces stacked bar plots showing the proportion of infested and non-infested hosts, facilitating the assessment of prevalence patterns across hierarchical combinations.

Usage

para_explo_prev(dataset, sp_cols, group_vars = NULL,
 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.

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 dataset into long format and calculates prevalence as the proportion of infested hosts (hosts with parasite counts > 0) relative to the number of analyzed hosts for each parasite taxon and grouping combination. For each combination, the function generates:

  • The proportion of infested hosts.

  • The proportion of non-infested hosts.

Faceting is applied to display each parasite taxon and grouping combination in separate panels. Special cases are handled as follows:

  • When no observations are available (all values are missing or the combination is absent), a message is displayed indicating that the data were not analyzed.

  • When only one host is available, a message is displayed indicating that the sample size is insufficient for prevalence estimation.

  • When all observed values are zero, a message is displayed indicating that the parasite was not recorded for that combination.

All proportions are expressed on a 0–1 scale. These plots are intended for exploratory purposes and should not be used as formal inference tools.

Value

A ggplot2 object containing the generated faceted stacked bar 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_prev(para_data$dataset,
               sp_cols = c("Sp1", "Sp2"),
               group_vars = c("Site", "Sp_host"),
               n_col = 4,
               verbose = TRUE)

#Species 3 and 4

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


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