
Atomic rarefaction / extrapolation plot (internal)
Source:R/rarefractionplot.R
RarefactionPlotAtomic.RdCore implementation for drawing a single rarefaction (or extrapolation)
curve from biodiversity data. This is the workhorse behind the exported
RarefactionPlot — it takes a single fortifed data frame
(produced by fortify() on an iNEXT object)
and returns a ggplot object.
The function renders three types of curves:
Sample-size-based (
type = 1) — species diversity as a function of sample size (number of individuals or sampling units), with rarefaction (interpolation) and extrapolation segments.Sample completeness (
type = 2) — sample coverage as a function of sample size.Coverage-based (
type = 3) — species diversity as a function of sample coverage.
Observed data points are marked with geom_point() (shape per group),
the rarefaction / extrapolation lines are drawn with geom_line()
using a solid/dashed linetype to distinguish the two phases, and
confidence intervals are rendered as semi-transparent ribbons when
se = TRUE and the fortifed data contains y.lwr / y.upr
columns.
Usage
RarefactionPlotAtomic(
data,
type = 1,
se = TRUE,
group_by = "group",
group_name = NULL,
pt_size = 3,
line_width = 1,
theme = "theme_this",
theme_args = list(),
palette = "Spectral",
palcolor = NULL,
palreverse = FALSE,
alpha = 0.2,
facet_by = NULL,
facet_scales = "fixed",
facet_ncol = NULL,
facet_nrow = NULL,
facet_byrow = TRUE,
aspect.ratio = 1,
legend.position = "right",
legend.direction = "vertical",
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
...
)Arguments
- data
A data frame produced by
fortify()on aniNEXTobject. Expected to contain columnsx(sample size or coverage),y(diversity or coverage estimate),Method("Observed","Rarefaction","Extrapolation"),y.lwr/y.upr(confidence bounds, optional),datatype("abundance"or"incidence"),group(assemblage name, renamed fromAssemblage), andq(diversity order, renamed fromOrder.q).- type
An integer specifying the curve type:
1for sample-size-based rarefaction/extrapolation,2for sample completeness, or3for coverage-based rarefaction/extrapolation. A vector of types can be passed and the data will be fortifed for all of them; faceting or splitting then separates the panels. Default:1.- se
A logical value indicating whether to display confidence intervals as semi-transparent ribbons around the estimated curve. When
NULL(the default), it resolves toTRUEif the fortifed data containsy.lwrandy.uprcolumns, andFALSEotherwise.- group_by
A character vector specifying how to group the data for colouring the lines. Must be one or both of
"q"(diversity order) and"group"(assemblage/site). Multiple values are concatenated withgroup_by_sep. WhenNULL, a dummy".group"column is created and the legend is hidden. Default:"group".- group_name
A character string used as the title for the colour (and shape) legend. When
NULL(the default), the value ofgroup_byis used.- pt_size
A numeric value specifying the size of the observed-data points. Default:
3.- line_width
A numeric value specifying the width of the rarefaction / extrapolation lines. Default:
1.- theme
A character string or a theme class (i.e. ggplot2::theme_classic) specifying the theme to use. Default is "theme_this".
- theme_args
A list of arguments to pass to the theme function.
- palette
A character string specifying the colour palette to use. A named list or vector can be used to specify palettes for different
split_bylevels in the exportedRarefactionPlot. Default:"Spectral".- palcolor
A character string specifying the color to use in the palette. A named list can be used to specify the colors for different
split_byvalues. If some values are missing, the values from the palette will be used (palcolor will be NULL for those values).- palreverse
A logical value indicating whether to reverse the palette. Default is FALSE.
- alpha
A numeric value between 0 and 1 specifying the transparency of the confidence-interval ribbon fill. Default:
0.2.- facet_by
A character string specifying the column name of the data frame to facet the plot. Otherwise, the data will be split by
split_byand generate multiple plots and combine them into one usingpatchwork::wrap_plots- facet_scales
Whether to scale the axes of facets. Default is "fixed" Other options are "free", "free_x", "free_y". See
ggplot2::facet_wrap- facet_ncol
A numeric value specifying the number of columns in the facet. When facet_by is a single column and facet_wrap is used.
- facet_nrow
A numeric value specifying the number of rows in the facet. When facet_by is a single column and facet_wrap is used.
- facet_byrow
A logical value indicating whether to fill the plots by row. Default is TRUE.
- aspect.ratio
A numeric value specifying the aspect ratio of the plot.
- legend.position
A character string specifying the position of the legend. if
waiver(), for single groups, the legend will be "none", otherwise "right".- legend.direction
A character string specifying the direction of the legend.
- title
A character string specifying the title of the plot. A function can be used to generate the title based on the default title. This is useful when split_by is used and the title needs to be dynamic.
- subtitle
A character string specifying the subtitle of the plot.
- xlab
A character string specifying the x-axis label.
- ylab
A character string specifying the y-axis label.
- ...
Additional arguments (currently unused in the atomic function; accepted for forward compatibility with the exported wrapper).
Architecture
ggplot dispatch — selects
gglogger::ggplotorggplot2::ggplotbased ongetOption("plotthis.gglogger.enabled").Axis labels — set according to the combination of
typeand the data'sdatatypeattribute ("abundance"vs."incidence"):type = 2: x = "Number of individuals" or "Number of sampling units", y = "Sample coverage".type = 3 || 4: x = "Sample coverage", y = "Species diversity".type = 1(abundance): x = "Number of individuals", y = "Species diversity".type = 1(incidence): x = "Number of sampling units", y = "Species diversity".
Group name fallback — if
group_nameisNULL, it is set to the value ofgroup_by(i.e."q"or"group").Base ggplot — initialises
ggplot(data, aes(x, y, color = group_by)).Observed data points —
geom_point()on rows whereMethod == "Observed", with shape mapped to the group variable.Colour scale —
scale_color_manual()usingpalette_this(). The legend is suppressed whengroup_byis the dummy".group".Shape scale —
scale_shape_discrete()with the same legend-suppression logic.Rarefaction / extrapolation lines —
geom_line()with linetype mapped to theltycolumn ("Rarefaction"vs."Extrapolation").Linetype scale —
scale_linetype_manual()withsolidanddashedvalues, legend key width set to 1 cm.Theme and labels —
do_call(theme, theme_args),panel.grid.major(grey80 dashed), aspect ratio, legend position / direction, and title / subtitle.Confidence ribbon — when
se = TRUE, ageom_ribbon(aes(ymin = y.lwr, ymax = y.upr, fill = group_by))is added with the same per-group palette at transparencyalpha.Dimension calculation —
calculate_plot_dimensions()computesheight/widthattributes frombase_height = 4.5,aspect.ratio, and legend metrics.Faceting —
facet_plot()wraps the plot withfacet_wrap/facet_gridiffacet_byis provided.