Skip to contents

Creates a set of lollipop-style density plots showing the distribution of a specified bionomics variable (e.g., endophagy, endophily, parous rate) across mosquito species, grouped by higher-level species complexes. Each complex is displayed as a separate subplot with consistent scaling and color mapping. Optionally saves the final combined plot as a PNG file.

Usage

plot_lollipop(data, varname, path = NULL)

Arguments

data

A list containing the following elements: - `data.req`: A data frame with observation data. Must include columns `name`, `value`, and a density column named following the pattern `<varname>.den` (e.g., `"endophagy.den"`). - `species_complex`: A data frame linking species names to their corresponding higher-level complexes, with columns `species` and `complex`.

varname

A character string indicating the base name of the behavioral variable to plot (e.g., `"endophagy"`, `"parous_rate"`). The corresponding density column must be present in `data$data.req`.

path

Optional. A character string giving the file path where the final combined PNG plot should be saved. If `NULL`, the plot is not saved.

Value

A combined `ggplot` object containing one lollipop density plot per species complex, aligned vertically and annotated with appropriate axis and variable labels.

Details

- Species names prefixed with `"unlabeled"` are cleaned before plotting. - Species are matched to colors from a palette file named `"new_palette_density_plots.csv"`. Species missing from the palette are automatically assigned a default grey color. - The resulting plots are combined and annotated using **cowplot**. - If `path` is provided, the function saves the figure as a high-resolution PNG.