convert_depth_to_ordered_factor: Converts values in the DEPTH column to an ordered factor

View source: R/convert_DEPTH_to_ordered_factor.R

convert_depth_to_ordered_factorR Documentation

Converts values in the DEPTH column to an ordered factor

Description

This function simplifies converting the DEPTH column from class numeric, factor, or character to an ordered factor, which is preferred for using the function plot_variables_at_depth().

Usage

convert_depth_to_ordered_factor(dat.tidy)

Arguments

dat.tidy

Data in tidy format, as returned by the function convert_to_tidydata(). Must include at least one column: DEPTH (factor, character, or numeric).

Details

To use the function plot_variables_at_depth(), DEPTH must be a factor because DEPTH is mapped to a discrete color scale. For the legend to display correctly (e.g. depths arranged from shallow to deep), DEPTH must be an ordered factor.

The DEPTH column may be values that can be coerced to class numeric, qualitative descriptors, or a combination of both. A different level will be assigned to each of the unique values of DEPTH. This could cause some confusion when DEPTH includes numeric and qualitative values, for example because the level (colour) for "Surface" will not the same as the level for "2 m").

Qualitative DEPTH values will be standardized to "Surface", "Sub-surface", "Middle", and "Bottom". Accepted qualitative DEPTH values are "Bottom", "bottom", "Middle", "middle", "Sub surface", "Sub-Surface", Sub-surface", "sub surface", "sub-surface", "Sub", "sub", "Surface", and "surface". Other values will cause the function to stop with an error message.

For numeric depths: the smallest value is assigned to the first level, the second smallest value is assigned to the second level, and so on.

For qualitative depths: the assigned order is "Surface" < "Sub-surface" < "Middle" < "Bottom".

Value

Returns dat.tidy, with the DEPTH column converted to an ordered factor.

Author(s)

Danielle Dempsey

See Also

Other format: convert_to_tidydata(), format_for_opendata(), trim_data()


Centre-for-Marine-Applied-Research/strings documentation built on Aug. 21, 2023, 8 a.m.