Package 'ggcircular'

Title: A 'ggplot2' Extension for Circular, Cylindrical and Toroidal Data
Description: Provides a 'ggplot2' grammar for circular, axial and directional data, including rose diagrams, circular densities, mean directions, confidence arcs, theoretical circular distributions, movement data visualizations, and displays for circular-linear and circular-circular dependence on cylinders and tori.
Authors: Aurélien Nicosia [aut, cre]
Maintainer: Aurélien Nicosia <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2026-09-19 09:14:35 UTC
Source: https://github.com/aureliennicosiaulaval/ggcircular

Help Index


Alignment index for two angular variables

Description

Computes ⁠|mean(exp(i * (phi - theta)))|⁠, a scalar summary of circular alignment between two angular variables.

Usage

alignment_index(theta, phi)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

Value

A numeric scalar between 0 and 1.

See Also

Other directional dependence indicators: conditional_variation_index(), local_circ_moment()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
alignment_index(dat$theta, dat$phi)

Signed angular difference

Description

Computes the signed difference x - y on a periodic scale. With the default period, values are returned in ⁠[-pi, pi)⁠.

Usage

angular_difference(x, y, period = 2 * pi)

Arguments

x, y

Numeric vectors of angles.

period

Positive numeric period.

Value

A numeric vector following R recycling rules.

See Also

Other angle utilities: angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()

Examples

angular_difference(0, 3 * pi / 2)

Circular angular distance

Description

Computes the non-negative angular distance between x and y. With the default period, values are returned in ⁠[0, pi]⁠.

Usage

angular_distance(x, y, period = 2 * pi)

Arguments

x, y

Numeric vectors of angles.

period

Positive numeric period.

Value

A non-negative numeric vector.

See Also

Other angle utilities: angular_difference(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()

Examples

angular_distance(0, 3 * pi / 2)

Simulated animal movement steps

Description

Simulated tracks for three individuals with derived step length, bearing and turn angle features.

Usage

animal_steps

Format

A tibble with 600 rows and 8 variables:

id

Animal identifier.

time

Step index.

x, y

Cartesian coordinates.

step_length

Euclidean step length.

bearing

Movement bearing in radians under the mathematical convention.

turn_angle

Signed turn angle in radians.

state

Latent movement state label.

Source

Simulated for package examples.


Convert posterior draws to circular draws

Description

Converts objects supported by posterior::as_draws_df() into a long tibble of normalized angular draws.

Usage

as_circular_draws(draws, variables = NULL, period = 2 * pi, origin = 0)

Arguments

draws

Posterior draws object.

variables

Optional variables to keep.

period

Angular period.

origin

Lower bound of the normalized interval.

Value

A tibble with draw identifiers, .variable and .angle.

See Also

Other posterior helpers: autoplot_circular_draws(), summarise_circular_draws()


Coerce to step data

Description

Thin wrapper around mutate_directional_features() for pipelines where a more explicit movement-data verb is useful.

Usage

as_step_data(
  data,
  x,
  y,
  id = NULL,
  time = NULL,
  angle_convention = c("mathematical", "bearing")
)

Arguments

data

A data frame.

x, y

Coordinate columns.

id

Optional individual identifier column.

time

Optional time column used for sorting within individual.

angle_convention

Angle convention passed to compute_bearing().

Value

A tibble with movement features.

See Also

Other movement helpers: augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Circular model helper generics

Description

Lightweight generics reserved for future integration with angular regression packages. The default methods fail with an explicit message rather than silently returning incomplete output.

Usage

augment_circular(x, ...)

tidy_circular(x, ...)

glance_circular(x, ...)

Arguments

x

A model or circular object.

...

Additional arguments passed to methods.

Value

Method-dependent tibble output.

See Also

Other circular model helpers: circular_model_diagnostics(), circular_residuals()


Augment momentuHMM fits with angular states

Description

Extracts an angle column and inferred states from a fitted momentuHMM model. The function uses momentuHMM::viterbi() by default and adds state probabilities when momentuHMM::stateProbs() is available.

Usage

augment_momentuHMM_angles(
  object,
  data = NULL,
  angle = NULL,
  state_method = c("viterbi", "stateProbs"),
  ...
)

Arguments

object

A fitted momentuHMM object.

data

Optional data frame. If NULL, object$data is used.

angle

Optional name of the angle column.

state_method

State extraction method.

...

Reserved for future methods.

Value

A tibble with .angle, .state and optional state probabilities.

See Also

Other movement helpers: as_step_data(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Autoplot circular data

Description

Creates a quick diagnostic plot for a numeric vector of circular angles.

Usage

autoplot_circular(
  theta,
  bins = 24,
  density = TRUE,
  mean = TRUE,
  axial = FALSE,
  ...
)

Arguments

theta

Numeric vector of angles in radians.

bins

Number of rose diagram bins.

density

Should a circular density estimate be added?

mean

Should the mean direction be added?

axial

Should the data be treated as axial, modulo pi?

...

Additional arguments currently ignored.

Value

A ggplot object.

Examples

autoplot_circular(wind_directions$direction)

Autoplot circular posterior draws

Description

Autoplot circular posterior draws

Usage

autoplot_circular_draws(
  draws,
  variables = NULL,
  type = c("density", "interval"),
  axial = FALSE,
  ...
)

Arguments

draws

Circular draws or posterior draws.

variables

Optional variables to plot.

type

Plot type.

axial

Should draws be treated as axial, modulo pi?

...

Additional arguments passed to as_circular_draws() when needed.

Value

A ggplot object.

See Also

Other posterior helpers: as_circular_draws(), summarise_circular_draws()


Plot bootstrap uncertainty for a statistical orbit

Description

Plot bootstrap uncertainty for a statistical orbit

Usage

## S3 method for class 'bootstrap_stat_orbit'
autoplot(
  object,
  ...,
  quantity = c("mu", "sigma"),
  base_size = 11,
  ribbon_fill = "#8fb4ff",
  line_colour = "#123f9b"
)

Arguments

object

Object returned by bootstrap_stat_orbit().

...

Reserved for future extensions.

quantity

Either "mu" or "sigma".

base_size

Base font size.

ribbon_fill

Ribbon fill colour.

line_colour

Line colour.

Value

A ggplot object.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), marginal_support_data(), plot_marginal_support(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_cylindrical(n = 60, seed = 1)
boot <- bootstrap_stat_orbit(dat$theta, dat$x, n_boot = 5, n_theta = 12, seed = 1)
ggplot2::autoplot(boot)

Plot bootstrap uncertainty for a toroidal ridge

Description

Plot bootstrap uncertainty for a toroidal ridge

Usage

## S3 method for class 'bootstrap_toroidal_ridge'
autoplot(
  object,
  ...,
  quantity = c("rho", "ridge"),
  base_size = 11,
  ribbon_fill = "#99d9d0",
  line_colour = "#0f766e"
)

Arguments

object

Object returned by bootstrap_toroidal_ridge().

...

Reserved for future extensions.

quantity

Either "rho" or "ridge".

base_size

Base font size.

ribbon_fill

Ribbon fill colour.

line_colour

Line colour.

Value

A ggplot object.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), marginal_support_data(), plot_marginal_support(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_toroidal(n = 60, scenario = "diagonal", seed = 1)
boot <- bootstrap_toroidal_ridge(dat$theta, dat$phi, n_boot = 5, n_theta = 12, n_phi = 12, seed = 1)
ggplot2::autoplot(boot)

Plot diagnostic atlas data

Description

Plot diagnostic atlas data

Usage

## S3 method for class 'diagnostic_atlas_data'
autoplot(
  object,
  ...,
  point_alpha = 0.2,
  point_size = 0.7,
  smooth = TRUE,
  base_size = 11
)

Arguments

object

Object returned by diagnostic_atlas_data().

...

Reserved for future extensions.

point_alpha

Point transparency.

point_size

Point size.

smooth

Should a loess smooth be added for cylindrical data?

base_size

Base font size.

Value

A ggplot object.

See Also

Other directional diagnostics: diagnostic_atlas_data(), diagnostic_scenarios(), plot_classical_comparison(), plot_diagnostic_atlas(), simulate_cyl_diagnostic(), simulate_tor_diagnostic()

Examples

atlas <- diagnostic_atlas_data("cylindrical", n = 20, seed = 1)
ggplot2::autoplot(atlas)

Simulated axial orientations

Description

Simulated axial orientation data, such as fiber or fault orientations, stored modulo pi.

Usage

axial_orientations

Format

A tibble with 300 rows and 3 variables:

sample

Sample identifier.

orientation

Axial orientation in radians, modulo pi.

group

Group label.

Source

Simulated for package examples.


Bootstrap a statistical orbit

Description

Bootstrap a statistical orbit

Usage

bootstrap_stat_orbit(
  theta,
  x,
  n_boot = 100,
  n_theta = 181,
  kappa = 20,
  seed = NULL
)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_boot

Number of bootstrap resamples.

n_theta

Number of angular grid points.

kappa

Circular concentration for local weighting.

seed

Optional random seed.

Value

A data frame with point estimates and bootstrap intervals. The returned object has class bootstrap_stat_orbit.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_toroidal_ridge(), marginal_support_data(), plot_marginal_support(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_cylindrical(n = 60, seed = 1)
bootstrap_stat_orbit(dat$theta, dat$x, n_boot = 5, n_theta = 12, seed = 1)

Bootstrap a toroidal conditional ridge

Description

Bootstrap a toroidal conditional ridge

Usage

bootstrap_toroidal_ridge(
  theta,
  phi,
  n_boot = 100,
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  level = 0.95,
  seed = NULL
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_boot

Number of bootstrap resamples.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

level

Coverage level for the pointwise circular bootstrap interval.

seed

Optional random seed.

Value

A data frame with ridge and local concentration intervals. The returned object has class bootstrap_toroidal_ridge.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), marginal_support_data(), plot_marginal_support(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_toroidal(n = 60, scenario = "diagonal", seed = 1)
bootstrap_toroidal_ridge(dat$theta, dat$phi, n_boot = 5, n_theta = 12, n_phi = 12, seed = 1)

Convert Cartesian coordinates to spherical coordinates

Description

Convert Cartesian coordinates to spherical coordinates

Usage

cartesian_to_spherical(
  x,
  y,
  z,
  convention = c("azimuth_colatitude", "azimuth_elevation")
)

Arguments

x, y, z

Cartesian coordinates.

convention

Output convention for phi.

Value

A tibble with theta, phi and radius.

See Also

Other spherical helpers: spherical_summary(), spherical_to_cartesian()


Check an angle vector

Description

Check an angle vector

Usage

check_angle(x, allow_na = TRUE)

Arguments

x

Object to check.

allow_na

Should missing values be allowed?

Value

Invisibly returns x if the check succeeds.

See Also

Other angle utilities: angular_difference(), angular_distance(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()


Confidence interval for a circular mean

Description

Computes an approximate confidence interval for a circular mean. The large sample method uses a normal approximation on the mean direction, while the bootstrap method resamples angles and forms an interval from angular deviations around the sample mean. These intervals are exploratory; they are not reliable when the mean resultant length is close to zero and the mean direction is weakly identified.

Usage

circular_mean_ci(
  x,
  level = 0.95,
  method = c("large_sample", "bootstrap"),
  R = 999,
  axial = FALSE,
  na.rm = TRUE,
  seed = NULL
)

Arguments

x

Numeric vector of angles in radians.

level

Confidence level.

method

Interval method.

R

Number of bootstrap resamples.

axial

Should data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

seed

Optional random seed for the bootstrap.

Value

A tibble with mean, lower, upper, level, method, n and Rbar.

See Also

Other circular summaries: circular_sd(), circular_summary(), circular_variance(), estimate_kappa(), mean_direction(), mean_resultant_length(), resultant_length()


Circular model diagnostics

Description

Summarizes circular residual diagnostics for supported angular model objects.

Usage

circular_model_diagnostics(object, data = NULL, ...)

Arguments

object

A supported angular model object.

data

Optional data frame to bind to the diagnostic columns.

...

Reserved for future methods.

Value

A tibble with residual mean direction, resultant length, circular variance and maximum absolute circular residual.

See Also

Other circular model helpers: augment_circular(), circular_residuals()


Circular residuals for angular models

Description

Extracts observed angles, fitted angles and signed circular residuals from supported angular model objects. The function currently supports objects produced by the optional CircularRegression package when their fitted values are stored in a mui component.

Usage

circular_residuals(object, data = NULL, ...)

Arguments

object

A supported angular model object.

data

Optional data frame to bind to the diagnostic columns.

...

Reserved for future methods.

Value

A tibble with .observed, .fitted, .resid, .abs_resid, .index and .model_class.

See Also

Other circular model helpers: augment_circular(), circular_model_diagnostics()

Examples

fit <- structure(
  list(y = c(0, 0.2, 0.4), mui = c(0.05, 0.15, 0.5)),
  class = "angular"
)
circular_residuals(fit)

Circular standard deviation

Description

Uses the common descriptive statistic sqrt(-2 * log(Rbar)).

Usage

circular_sd(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

Circular standard deviation in radians.

See Also

Other circular summaries: circular_mean_ci(), circular_summary(), circular_variance(), estimate_kappa(), mean_direction(), mean_resultant_length(), resultant_length()


Summarize circular data

Description

Computes grouped circular summaries for an angle column. Existing dplyr groups are respected, and additional grouping variables can be supplied in ....

Usage

circular_summary(data, angle, ..., axial = FALSE, na.rm = TRUE)

Arguments

data

A data frame or tibble.

angle

Angle column, in radians.

...

Optional grouping variables.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

A tibble with columns n, mean, R, Rbar, variance, sd and kappa. The returned object also has class ggcircular_summary.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_variance(), estimate_kappa(), mean_direction(), mean_resultant_length(), resultant_length()

Examples

tibble::tibble(group = c("a", "a", "b"), theta = c(0, pi / 2, pi)) |>
  dplyr::group_by(group) |>
  circular_summary(theta)

Compute circular topography data

Description

Compute circular topography data

Usage

circular_topography_data(theta, x, conditional = TRUE, ...)

Arguments

theta

Angles in radians.

x

Real-valued response.

conditional

If TRUE, rows are normalized to estimate f(x | theta).

...

Additional arguments passed to estimate_cyl_density().

Value

A data frame with columns theta, x and density.

See Also

Other cylindrical dependence helpers: estimate_cyl_density(), phase_loom_data(), stat_orbit_data()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
circular_topography_data(dat$theta, dat$x, n_theta = 24, n_x = 30)

Circular variance

Description

Circular variance

Usage

circular_variance(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

The circular variance 1 - Rbar.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_summary(), estimate_kappa(), mean_direction(), mean_resultant_length(), resultant_length()


Convert compass labels to radians

Description

Converts the eight standard compass labels N, NE, E, SE, S, SW, W and NW to bearing angles in radians, where zero is north and angles increase clockwise.

Usage

compass_to_rad(x)

Arguments

x

Character vector of compass labels.

Value

Numeric vector of bearing angles in radians.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()

Examples

compass_to_rad(c("N", "E", "S", "W"))

Compute bearings

Description

Compute bearings

Usage

compute_bearing(x, y, angle_convention = c("mathematical", "bearing"))

Arguments

x, y

Numeric coordinate vectors.

angle_convention

Angle convention. "mathematical" means zero is east and angles increase counterclockwise. "bearing" means zero is north and angles increase clockwise.

Value

Numeric vector of bearings in radians. The first value is NA.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_step_length(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Compute step lengths

Description

Compute step lengths

Usage

compute_step_length(x, y)

Arguments

x, y

Numeric coordinate vectors.

Value

Numeric vector of Euclidean step lengths. The first value is NA.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Compute turn angles

Description

Compute turn angles

Usage

compute_turn_angle(bearing, period = 2 * pi)

Arguments

bearing

Numeric vector of bearings in radians.

period

Angular period.

Value

Numeric vector of signed turn angles. The first value is NA.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Conditional variation index

Description

Computes a simple squared variation summary for a matrix of conditional densities across conditioning-grid rows.

Usage

conditional_variation_index(density_matrix)

Arguments

density_matrix

Matrix with rows representing conditioning-grid values and columns representing conditional density values.

Value

A non-negative numeric scalar.

See Also

Other directional dependence indicators: alignment_index(), local_circ_moment()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
est <- estimate_toroidal_density(dat$theta, dat$phi, n_theta = 12, n_phi = 12, conditional = TRUE)
conditional_variation_index(est$density)

Circular coordinate system

Description

Convenience wrapper around ggplot2::coord_polar() with arguments expressed in circular-data language.

Usage

coord_circular(
  zero = c("east", "north", "west", "south"),
  direction = c("counterclockwise", "clockwise"),
  start = NULL,
  clip = "on"
)

Arguments

zero

Direction corresponding to angle zero.

direction

Direction in which angles increase.

start

Optional start offset in radians. If supplied, it overrides zero.

clip

Should drawing be clipped to the plot panel?

Details

zero = "east" and direction = "counterclockwise" gives the usual mathematical convention: zero points east and positive angles rotate toward north. zero = "north" and direction = "clockwise" gives the usual bearing convention used for compass directions.

Value

A ggplot2 coordinate object.

See Also

Other circular scales: scale_x_circular_radians()

Examples

coord_circular()
coord_circular(zero = "north", direction = "clockwise")

Convert degrees to radians

Description

Convert degrees to radians

Usage

deg_to_rad(x)

Arguments

x

Numeric vector in degrees.

Value

Numeric vector in radians.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()


Build diagnostic atlas data

Description

Build diagnostic atlas data

Usage

diagnostic_atlas_data(
  space = c("cylindrical", "toroidal"),
  n = 600,
  seed = 20260609
)

Arguments

space

Either "cylindrical" or "toroidal".

n

Number of observations per scenario.

seed

Optional random seed.

Value

A data frame with diagnostic scenarios and plotting columns. The returned object has class diagnostic_atlas_data.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_scenarios(), plot_classical_comparison(), plot_diagnostic_atlas(), simulate_cyl_diagnostic(), simulate_tor_diagnostic()

Examples

diagnostic_atlas_data("cylindrical", n = 20, seed = 1)

List built-in directional diagnostic scenarios

Description

List built-in directional diagnostic scenarios

Usage

diagnostic_scenarios()

Value

A data frame describing the built-in diagnostic scenarios.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_atlas_data(), plot_classical_comparison(), plot_diagnostic_atlas(), simulate_cyl_diagnostic(), simulate_tor_diagnostic()

Examples

diagnostic_scenarios()

Estimate a density on the cylinder

Description

Estimates a joint or conditional kernel density for circular-linear data on ⁠S1 x R⁠. The circular component uses von Mises weights and the linear component uses a Gaussian kernel.

Usage

estimate_cyl_density(
  theta,
  x,
  n_theta = 181,
  n_x = 200,
  kappa = 20,
  h = NULL,
  x_grid = NULL,
  conditional = TRUE
)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_theta

Number of angular grid points.

n_x

Number of linear grid points.

kappa

Circular concentration for the conditioning kernel.

h

Linear bandwidth. If NULL, a rule-of-thumb bandwidth is used.

x_grid

Optional grid for the linear response.

conditional

If TRUE, rows are normalized to estimate f(x | theta).

Value

A list with grids, a density matrix, a long data frame and smoothing metadata.

See Also

Other cylindrical dependence helpers: circular_topography_data(), phase_loom_data(), stat_orbit_data()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
est <- estimate_cyl_density(dat$theta, dat$x, n_theta = 24, n_x = 30)
str(est$data)

Estimate von Mises concentration

Description

Estimates the von Mises concentration parameter from the mean resultant length using the standard piecewise approximation described by Fisher (1993). This is a descriptive approximation and does not apply small-sample bias corrections or uncertainty quantification.

Usage

estimate_kappa(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

Estimated concentration parameter kappa.

References

Fisher, N. I. (1993). Statistical Analysis of Circular Data. Cambridge University Press.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_summary(), circular_variance(), mean_direction(), mean_resultant_length(), resultant_length()


Estimate a density on the torus

Description

Estimates a joint or conditional kernel density for circular-circular data on ⁠S1 x S1⁠. Both components use von Mises weights.

Usage

estimate_toroidal_density(
  theta,
  phi,
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  conditional = FALSE
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

conditional

If TRUE, rows are normalized to estimate f(phi | theta).

Value

A list with grids, a density matrix, a long data frame and smoothing metadata.

See Also

Other toroidal dependence helpers: toroidal_flow_data(), toroidal_ridge_data(), toroidal_topography_data()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
est <- estimate_toroidal_density(dat$theta, dat$phi, n_theta = 24, n_phi = 24)
str(est$data)

Fit a mixture of von Mises distributions

Description

Fits a finite mixture of von Mises components using an expectation maximization algorithm. For axial data, the algorithm fits doubled angles and returns component means on the original modulo-pi scale.

Usage

fit_vonmises_mixture(
  x,
  k = 2,
  weights = NULL,
  axial = FALSE,
  init = c("kmeans", "spaced"),
  nstart = 1,
  init_params = NULL,
  kappa_max = 10000,
  min_component_weight = 1e-08,
  max_iter = 200,
  tol = 1e-08,
  na.rm = TRUE,
  seed = NULL
)

Arguments

x

Numeric vector of angles in radians.

k

Number of mixture components.

weights

Optional non-negative observation weights.

axial

Should data be treated as axial, modulo pi?

init

Initialization method, either "kmeans" or "spaced".

nstart

Number of EM starts. The fit with the largest log-likelihood is retained.

init_params

Optional list or data frame with initial proportions, mu and kappa values.

kappa_max

Maximum fitted concentration. This caps nearly degenerate components.

min_component_weight

Minimum relative component weight before a component is reinitialized.

max_iter

Maximum number of EM iterations.

tol

Convergence tolerance on the log-likelihood.

na.rm

Should missing values be removed?

seed

Optional random seed used for initialization.

Value

An object of class ggcircular_vonmises_mixture.

See Also

Other circular distributions: stat_vonmises(), stat_vonmises_fit(), stat_vonmises_mixture()

Examples

fit <- fit_vonmises_mixture(wind_directions$direction, k = 2)
tidy_circular(fit)

Circular density layer

Description

Draws a circular density estimate as a line. This is a convenience wrapper around stat_circular_density().

Usage

geom_circular_density(
  mapping = NULL,
  data = NULL,
  stat = "circular_density",
  position = "identity",
  ...,
  method = c("kernel", "vonmises"),
  bw = NULL,
  adjust = 1,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

stat

Statistical transformation, usually "circular_density".

...

Additional arguments passed to the layer.

method

Density method. Currently "kernel" and "vonmises" both use a von Mises kernel estimator.

bw

Optional circular bandwidth. It is interpreted as 1 / sqrt(kappa).

adjust

Multiplicative adjustment applied to bw or to the automatic bandwidth scale.

n

Number of grid points.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer.

See Also

Other circular density layers: stat_circular_density()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  geom_circular_density()

Circular point and rug helpers

Description

Convenience layers for plotting angular observations at a fixed radius.

Usage

geom_circular_point(
  mapping = NULL,
  data = NULL,
  ...,
  radius = 1,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_circular_rug(
  mapping = NULL,
  data = NULL,
  ...,
  radius = 1,
  rug_length = 0.05,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to ggplot2::geom_segment().

radius

Radius at which points or rugs are drawn.

na.rm

Should missing values be silently removed?

rug_length

Radial length of rug marks.

Value

A ggplot2 layer.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_direction_arrow(), mutate_directional_features(), plot_state_angles()


Circular confidence arc

Description

Draws angular intervals as arcs at a fixed radius. Intervals crossing zero are split into two path segments.

Usage

geom_confidence_arc(
  mapping = NULL,
  data = NULL,
  ...,
  radius = 1,
  n = 200,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_circular_interval(
  mapping = NULL,
  data = NULL,
  ...,
  radius = 1,
  n = 200,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the path geometry.

radius

Default radius used when no radius or y aesthetic is supplied.

n

Number of points used to discretize each interval.

na.rm

Should missing interval endpoints be silently removed?

Value

A ggplot2 layer.

Examples

tibble::tibble(lower = 5.5, upper = 0.5) |>
  ggplot2::ggplot(ggplot2::aes(xmin = lower, xmax = upper)) +
  geom_confidence_arc()

Direction arrows

Description

Draws directional arrows from Cartesian coordinates and an angle.

Usage

geom_direction_arrow(
  mapping = NULL,
  data = NULL,
  ...,
  length = 1,
  arrow_length = grid::unit(0.15, "cm"),
  angle_convention = c("mathematical", "bearing"),
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to ggplot2::geom_segment().

length

Default arrow length when no length aesthetic is supplied.

arrow_length

Grid unit controlling the arrow head length.

angle_convention

Angle convention. "mathematical" means zero is east and angles increase counterclockwise. "bearing" means zero is north and angles increase clockwise.

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_circular_point(), mutate_directional_features(), plot_state_angles()

Examples

ggplot2::ggplot(animal_steps, ggplot2::aes(x = x, y = y, angle = bearing)) +
  geom_direction_arrow()

Mean direction layer

Description

Draws a radial segment at the circular mean direction. The segment length can be fixed or proportional to the mean resultant length.

Usage

geom_mean_direction(
  mapping = NULL,
  data = NULL,
  stat = "mean_direction",
  position = "identity",
  ...,
  length = c("resultant", "fixed"),
  radius = NULL,
  conf.int = FALSE,
  level = 0.95,
  axial = FALSE,
  arrow = TRUE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

stat

Statistical transformation, usually "mean_direction".

...

Additional arguments passed to the layer.

length

Should the displayed segment length be proportional to the mean resultant length ("resultant") or fixed ("fixed")?

radius

Optional maximum displayed radius.

conf.int

Should approximate confidence limits be computed?

level

Confidence level used when conf.int = TRUE.

axial

Should the data be treated as axial, modulo pi?

arrow

Should a small arrow head be drawn?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer.

See Also

Other mean direction layers: stat_mean_direction()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  geom_rose(bins = 16) +
  geom_mean_direction()

Add a phase loom layer

Description

Adds mass-flow curves for circular-linear data. Use this layer with ggplot2::ggplot(data, ggplot2::aes(x = theta, y = response)).

Usage

geom_phase_loom(
  mapping = NULL,
  data = NULL,
  position = "identity",
  n_sectors = 48,
  n_x_bins = 24,
  min_mass = 0.002,
  max_flows = 180,
  mass_type = c("joint", "conditional"),
  curvature = 0.24,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_sectors

Number of angular sectors.

n_x_bins

Number of bins for the linear response.

min_mass

Minimum mass to draw.

max_flows

Maximum number of flows to draw. Use NULL to draw all.

mass_type

Either "joint" or "conditional".

curvature

Curvature passed to ggplot2::geom_curve().

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other cylindrical dependence layers: stat_circular_topography(), stat_statistical_orbit(), stat_statistical_orbit_ribbon()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = x)) +
  geom_phase_loom(n_sectors = 12, n_x_bins = 8, min_mass = 0)

Rose diagram layer

Description

geom_rose() is a convenience wrapper around stat_rose() using a bar geometry. It is designed to be used with coord_circular() or ggplot2::coord_polar().

Usage

geom_rose(
  mapping = NULL,
  data = NULL,
  stat = "rose",
  position = "identity",
  ...,
  bins = 30,
  binwidth = NULL,
  boundary = 0,
  closed = TRUE,
  area = FALSE,
  normalize = c("count", "density", "proportion"),
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

stat

Statistical transformation, usually "rose".

...

Additional arguments passed to the layer.

bins

Number of bins over the circular period.

binwidth

Optional bin width in radians. If supplied, bins is ignored after the number of bins is inferred from the period.

boundary

Lower boundary for the first bin.

closed

Included for API compatibility. Values on the upper period boundary are wrapped into the first bin.

area

If TRUE, radial heights are square-root transformed so that visual area is closer to the selected frequency scale.

normalize

Which scale should be used for the computed radial y value: counts, densities or proportions.

axial

Should angles be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer.

See Also

Other rose diagram layers: stat_rose()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  geom_rose(bins = 16) +
  coord_circular()

Add a toroidal flow layer

Description

Adds rectangular flow curves from theta sectors to phi sectors. Use with aes(x = theta, y = phi).

Usage

geom_toroidal_flow(
  mapping = NULL,
  data = NULL,
  position = "identity",
  n_sectors = 32,
  min_mass = 0.002,
  mass_type = c("joint", "conditional"),
  curvature = 0.28,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_sectors

Number of angular sectors for both variables.

min_mass

Minimum mass to draw.

mass_type

Either "joint" or "conditional".

curvature

Curvature passed to ggplot2::geom_curve().

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other toroidal dependence layers: stat_toroidal_ridge(), stat_toroidal_topography()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = phi)) +
  geom_toroidal_flow(n_sectors = 12, min_mass = 0)

Convert hours to radians

Description

Convert hours to radians

Usage

hour_to_rad(x)

Arguments

x

Numeric vector in hours on a 24-hour clock.

Value

Numeric vector in radians.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()


Simulated hourly activity

Description

A reproducible simulated dataset of hourly activity converted to circular angles.

Usage

hourly_activity

Format

A tibble with 240 rows and 5 variables:

id

Individual identifier.

hour

Hour of day.

angle

Hour converted to radians.

activity

Activity level.

group

Group label.

Source

Simulated for package examples.


Test whether an object can represent angles

Description

Test whether an object can represent angles

Usage

is_angle(x)

Arguments

x

Object to test.

Value

TRUE when x is numeric and contains only finite values or NA.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), normalize_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()


Local circular moment

Description

Computes a kernel-weighted local circular moment of phi conditional on theta.

Usage

local_circ_moment(theta, phi, grid = NULL, kappa = 20)

Arguments

theta

Conditioning angles in radians.

phi

Target angles in radians.

grid

Optional angular grid. If NULL, a default grid is used.

kappa

Circular concentration for local weighting.

Value

A data frame with local real and imaginary components, mean direction mu, and local concentration rho.

See Also

Other directional dependence indicators: alignment_index(), conditional_variation_index()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
local_circ_moment(dat$theta, dat$phi, grid = seq(0, 2 * pi, length.out = 12))

Estimate angular marginal support

Description

Computes a kernel-weighted marginal support score along the conditioning angle. Low relative support marks angular regions where conditional displays should be interpreted cautiously.

Usage

marginal_support_data(
  theta,
  grid = NULL,
  n_theta = 181,
  kappa = 20,
  relative_threshold = 0.15
)

Arguments

theta

Conditioning angles in radians.

grid

Optional angular grid in radians.

n_theta

Number of grid points used when grid is NULL.

kappa

Circular concentration for local kernel weights.

relative_threshold

Relative support threshold used to flag low-support regions. With other ingredients fixed, the local standard error is approximately inflated by 1 / sqrt(relative_support). The default 0.15 corresponds to an inflation of about 2.58 relative to the best-supported direction; 0.25 is a more conservative threshold corresponding to about twofold inflation.

Value

A data frame with grid values, support, relative support and flags.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), plot_marginal_support(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_cylindrical(n = 60, seed = 1)
marginal_support_data(dat$theta, n_theta = 12)

Circular mean direction

Description

Computes the sample mean direction. For axial data, angles are doubled before computing the mean and the result is transformed back to the axial scale.

Usage

mean_direction(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

A single angle in radians, or NA_real_ when the mean is undefined.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_summary(), circular_variance(), estimate_kappa(), mean_resultant_length(), resultant_length()

Examples

mean_direction(c(0, pi / 4, pi / 2))

Mean resultant length

Description

Mean resultant length

Usage

mean_resultant_length(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

The mean resultant length Rbar, between 0 and 1 when defined.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_summary(), circular_variance(), estimate_kappa(), mean_direction(), resultant_length()


Add directional movement features

Description

Computes step length, bearing and turn angle from track coordinates. When id and time are supplied, records are sorted by individual and time before features are computed.

Usage

mutate_directional_features(
  data,
  x,
  y,
  id = NULL,
  time = NULL,
  angle_convention = c("mathematical", "bearing")
)

Arguments

data

A data frame.

x, y

Coordinate columns.

id

Optional individual identifier column.

time

Optional time column used for sorting within individual.

angle_convention

Angle convention passed to compute_bearing().

Value

A tibble with added step_length, bearing and turn_angle.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), plot_state_angles()

Examples

tibble::tibble(id = 1, time = 1:3, x = 0:2, y = 0) |>
  mutate_directional_features(x = x, y = y, id = id, time = time)

Normalize angles to a periodic interval

Description

normalize_angle() maps numeric angles to ⁠[origin, origin + period)⁠. The default period is 2 * pi, which is appropriate for directional circular data measured in radians.

Usage

normalize_angle(x, period = 2 * pi, origin = 0)

Arguments

x

Numeric vector of angles.

period

Positive numeric period. Use 2 * pi for directional data and pi for axial data.

origin

Lower bound of the target interval.

Value

A numeric vector with the same length as x.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), rad_to_compass(), rad_to_deg(), rad_to_hour()

Examples

normalize_angle(c(-pi, 0, 3 * pi))

Compute phase loom data

Description

Discretizes circular-linear observations into angular sectors and linear bins and returns binned mass flows for phase loom displays.

Usage

phase_loom_data(
  theta,
  x,
  n_sectors = 48,
  n_x_bins = 24,
  min_mass = 0.002,
  max_flows = 180,
  mass_type = c("joint", "conditional")
)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_sectors

Number of angular sectors.

n_x_bins

Number of linear bins.

min_mass

Minimum mass to retain.

max_flows

Maximum number of flows to retain. Use NULL to keep all.

mass_type

Either "joint" for joint masses or "conditional" for masses normalized within each angular sector.

Value

A data frame with sector identifiers, endpoints and mass values.

See Also

Other cylindrical dependence helpers: circular_topography_data(), estimate_cyl_density(), stat_orbit_data()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
phase_loom_data(dat$theta, dat$x, n_sectors = 12, n_x_bins = 8)

Plot circular topography

Description

Plot circular topography

Usage

plot_circular_topography(
  theta,
  x,
  conditional = TRUE,
  ...,
  palette = topography_palette(),
  base_size = 12,
  legend_position = "right",
  show_legend = TRUE
)

Arguments

theta

Angles in radians.

x

Real-valued response.

conditional

If TRUE, rows are normalized to estimate f(x | theta).

...

Additional arguments passed to estimate_cyl_density().

palette

Colour palette for density.

base_size

Base font size.

legend_position

Legend position.

show_legend

If FALSE, hide legends.

Value

A ggplot object.

See Also

Other cylindrical dependence plots: plot_circular_topography_3d(), plot_phase_loom(), plot_stat_orbit()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
plot_circular_topography(dat$theta, dat$x, n_theta = 24, n_x = 30)

Experimental 3D circular topography

Description

Displays a circular-linear conditional density on a cylinder. The function is experimental and is intended as a geometric companion to plot_circular_topography(), not as a replacement for the 2D display.

Usage

plot_circular_topography_3d(theta, x, radius = 1, conditional = TRUE, ...)

Arguments

theta

Angles in radians.

x

Real-valued response.

radius

Radius of the cylinder.

conditional

If TRUE, rows are normalized to estimate f(x | theta).

...

Additional arguments passed to circular_topography_data().

Value

A plotly htmlwidget.

See Also

Other cylindrical dependence plots: plot_circular_topography(), plot_phase_loom(), plot_stat_orbit()

Examples

dat <- simulate_cylindrical(n = 120, seed = 1)
plot_circular_topography_3d(dat$theta, dat$x, n_theta = 32, n_x = 40)

Plot a classical unfolded comparison

Description

Plot a classical unfolded comparison

Usage

plot_classical_comparison(data, space = c("cylindrical", "toroidal"))

Arguments

data

Data frame containing theta and either x or phi.

space

Either "cylindrical" or "toroidal".

Value

A ggplot object.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_atlas_data(), diagnostic_scenarios(), plot_diagnostic_atlas(), simulate_cyl_diagnostic(), simulate_tor_diagnostic()

Examples

dat <- simulate_cyl_diagnostic(n = 40, scenario = "smooth", seed = 1)
plot_classical_comparison(dat, "cylindrical")

Plot a diagnostic atlas

Description

Plot a diagnostic atlas

Usage

plot_diagnostic_atlas(
  space = c("cylindrical", "toroidal"),
  n = 600,
  seed = 20260609
)

Arguments

space

Either "cylindrical" or "toroidal".

n

Number of observations per scenario.

seed

Optional random seed.

Value

A ggplot object.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_atlas_data(), diagnostic_scenarios(), plot_classical_comparison(), simulate_cyl_diagnostic(), simulate_tor_diagnostic()

Examples

plot_diagnostic_atlas("toroidal", n = 20, seed = 1)

Plot angular marginal support

Description

Plot angular marginal support

Usage

plot_marginal_support(
  theta,
  grid = NULL,
  n_theta = 181,
  kappa = 20,
  relative_threshold = 0.15,
  base_size = 11
)

Arguments

theta

Conditioning angles in radians.

grid

Optional angular grid in radians.

n_theta

Number of grid points used when grid is NULL.

kappa

Circular concentration for local kernel weights.

relative_threshold

Relative support threshold used to flag low-support regions.

base_size

Base font size.

Value

A ggplot object.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), marginal_support_data(), sensitivity_bandwidth_grid(), simulate_independence_lineup()

Examples

dat <- simulate_cylindrical(n = 60, seed = 1)
plot_marginal_support(dat$theta, n_theta = 12)

Plot a phase loom

Description

Plot a phase loom

Usage

plot_phase_loom(
  theta,
  x,
  n_sectors = 48,
  n_x_bins = 24,
  min_mass = 0.002,
  max_flows = 180,
  mass_type = c("joint", "conditional"),
  palette = flow_palette(),
  base_size = 12,
  legend_position = "right",
  show_legend = TRUE
)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_sectors

Number of angular sectors.

n_x_bins

Number of linear bins.

min_mass

Minimum mass to retain.

max_flows

Maximum number of flows to retain. Use NULL to keep all.

mass_type

Either "joint" for joint masses or "conditional" for masses normalized within each angular sector.

palette

Colour palette for response levels.

base_size

Base font size.

legend_position

Legend position.

show_legend

If FALSE, hide legends.

Value

A ggplot object.

See Also

Other cylindrical dependence plots: plot_circular_topography(), plot_circular_topography_3d(), plot_stat_orbit()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
plot_phase_loom(dat$theta, dat$x, n_sectors = 12, n_x_bins = 8)

Plot a statistical orbit

Description

Plot a statistical orbit

Usage

plot_stat_orbit(theta, x, n_theta = 181, kappa = 20, base_size = 12)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_theta

Number of angular grid points.

kappa

Circular concentration for local weighting.

base_size

Base font size.

Value

A ggplot object.

See Also

Other cylindrical dependence plots: plot_circular_topography(), plot_circular_topography_3d(), plot_phase_loom()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
plot_stat_orbit(dat$theta, dat$x, n_theta = 24)

Plot angular distributions by state

Description

Convenience function for visualizing angles by observed or inferred states.

Usage

plot_state_angles(
  data,
  angle,
  state,
  type = c("rose", "density", "mean"),
  bins = 24,
  axial = FALSE
)

Arguments

data

A data frame.

angle

Angle column.

state

State or group column.

type

Plot type.

bins

Number of bins for rose diagrams.

axial

Should data be treated as axial, modulo pi?

Value

A ggplot object.

See Also

Other movement helpers: as_step_data(), augment_momentuHMM_angles(), compute_bearing(), compute_step_length(), compute_turn_angle(), geom_circular_point(), geom_direction_arrow(), mutate_directional_features()


Plot toroidal flow

Description

Plot toroidal flow

Usage

plot_toroidal_flow(
  theta,
  phi,
  n_sectors = 32,
  min_mass = 0.002,
  mass_type = c("joint", "conditional"),
  palette = flow_palette(),
  base_size = 12,
  legend_position = "right",
  show_legend = TRUE
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_sectors

Number of sectors for both angles.

min_mass

Minimum mass to retain.

mass_type

Either "joint" for joint masses or "conditional" for masses normalized within each theta sector.

palette

Colour palette for theta sectors.

base_size

Base font size.

legend_position

Legend position.

show_legend

If FALSE, hide legends.

Value

A ggplot object.

See Also

Other toroidal dependence plots: plot_toroidal_ridge(), plot_toroidal_topography(), plot_toroidal_topography_3d()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
plot_toroidal_flow(dat$theta, dat$phi, n_sectors = 12)

Plot a conditional toroidal ridge

Description

Plot a conditional toroidal ridge

Usage

plot_toroidal_ridge(
  theta,
  phi,
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  tie_tolerance = 0.01,
  density_palette = c("#f6f7f9", "#d7dce1", "#aab4bf", "#6d7f91", "#33485c"),
  rho_palette = ridge_palette(),
  base_size = 12,
  legend_position = "right",
  show_legend = TRUE
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

tie_tolerance

Relative tolerance used to flag near-tied distinct local modes without changing the selected ridge.

density_palette

Colour palette for the density background.

rho_palette

Colour palette for local concentration.

base_size

Base font size.

legend_position

Legend position.

show_legend

If FALSE, hide legends.

Value

A ggplot object.

See Also

Other toroidal dependence plots: plot_toroidal_flow(), plot_toroidal_topography(), plot_toroidal_topography_3d()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
plot_toroidal_ridge(dat$theta, dat$phi, n_theta = 24, n_phi = 24)

Plot toroidal topography

Description

Plot toroidal topography

Usage

plot_toroidal_topography(
  theta,
  phi,
  conditional = FALSE,
  ...,
  palette = topography_palette(),
  base_size = 12,
  legend_position = "right",
  show_legend = TRUE
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

conditional

If TRUE, rows are normalized to estimate f(phi | theta).

...

Additional arguments passed to estimate_toroidal_density().

palette

Colour palette for density.

base_size

Base font size.

legend_position

Legend position.

show_legend

If FALSE, hide legends.

Value

A ggplot object.

See Also

Other toroidal dependence plots: plot_toroidal_flow(), plot_toroidal_ridge(), plot_toroidal_topography_3d()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
plot_toroidal_topography(dat$theta, dat$phi, n_theta = 24, n_phi = 24)

Experimental 3D toroidal topography

Description

Displays a circular-circular density on a torus. Colour represents the estimated density and, by default, a small radial displacement also highlights high-density regions. The function is experimental and is intended as a geometric companion to plot_toroidal_topography().

Usage

plot_toroidal_topography_3d(
  theta,
  phi,
  major_radius = 1,
  minor_radius = 0.35,
  density_scale = 0.15,
  conditional = TRUE,
  ...
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

major_radius

Major torus radius.

minor_radius

Minor torus radius.

density_scale

Non-negative radial displacement applied after scaling density to ⁠[0, 1]⁠. Use 0 for colour-only density encoding.

conditional

If TRUE, rows are normalized to estimate f(phi | theta).

...

Additional arguments passed to toroidal_topography_data().

Value

A plotly htmlwidget.

See Also

Other toroidal dependence plots: plot_toroidal_flow(), plot_toroidal_ridge(), plot_toroidal_topography()

Examples

dat <- simulate_toroidal(n = 120, seed = 1)
plot_toroidal_topography_3d(dat$theta, dat$phi, n_theta = 32, n_phi = 32)

Convert radians to compass labels

Description

Converts angles to the nearest label among labels. Angles are interpreted as bearings by default: zero is north and angles increase clockwise.

Usage

rad_to_compass(x, labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))

Arguments

x

Numeric vector of angles in radians.

labels

Character vector of equally spaced labels.

Value

Character vector of labels.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_deg(), rad_to_hour()

Examples

rad_to_compass(c(0, pi / 2, pi))

Convert radians to degrees

Description

Convert radians to degrees

Usage

rad_to_deg(x)

Arguments

x

Numeric vector in radians.

Value

Numeric vector in degrees.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_hour()


Convert radians to hours

Description

Convert radians to hours

Usage

rad_to_hour(x)

Arguments

x

Numeric vector in radians.

Value

Numeric vector in hours on a 24-hour clock.

See Also

Other angle utilities: angular_difference(), angular_distance(), check_angle(), compass_to_rad(), deg_to_rad(), hour_to_rad(), is_angle(), normalize_angle(), rad_to_compass(), rad_to_deg()


Rayleigh test for circular uniformity

Description

Performs the one-sample Rayleigh test for non-uniformity. The test is most sensitive to unimodal departures from circular uniformity. The returned object follows the base htest structure.

Usage

rayleigh_test(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

An object of class htest.

See Also

Other circular tests: stat_circular_test(), watson_williams_test()


Resultant length

Description

Resultant length

Usage

resultant_length(x, axial = FALSE, na.rm = TRUE)

Arguments

x

Numeric vector of angles in radians.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be removed?

Value

The sample resultant length R.

See Also

Other circular summaries: circular_mean_ci(), circular_sd(), circular_summary(), circular_variance(), estimate_kappa(), mean_direction(), mean_resultant_length()


Circular x scales

Description

These scales label angular x axes in radians, degrees, hours or compass directions.

Usage

scale_x_circular_radians(
  breaks = ggplot2::waiver(),
  labels = ggplot2::waiver(),
  limits = c(0, 2 * pi),
  ...
)

scale_x_circular_degrees(
  breaks = ggplot2::waiver(),
  labels = ggplot2::waiver(),
  limits = c(0, 2 * pi),
  ...
)

scale_x_circular_hours(
  breaks = ggplot2::waiver(),
  labels = ggplot2::waiver(),
  limits = c(0, 2 * pi),
  ...
)

scale_x_circular_compass(
  breaks = ggplot2::waiver(),
  labels = ggplot2::waiver(),
  limits = c(0, 2 * pi),
  ...
)

Arguments

breaks

Break positions in radians.

labels

Break labels.

limits

Scale limits in radians.

...

Additional arguments passed to ggplot2::scale_x_continuous().

Value

A ggplot2 scale.

See Also

Other circular scales: coord_circular()

Examples

scale_x_circular_radians()

Select smoothing parameters for circular-linear conditional density

Description

Ranks candidate smoothing parameters by K-fold conditional log-likelihood.

Usage

select_cyl_smoothing(
  theta,
  x,
  kappa_values = c(6, 8, 12, 16, 24, 36),
  h_values = NULL,
  n_folds = 5,
  seed = NULL
)

Arguments

theta

Conditioning angles in radians.

x

Linear response.

kappa_values

Candidate circular concentration values.

h_values

Candidate linear bandwidth values. If NULL, a small grid is built around the rule-of-thumb bandwidth used by estimate_cyl_density().

n_folds

Number of cross-validation folds.

seed

Optional random seed for fold assignment.

Value

A data frame ranked by decreasing mean held-out log score. The returned object has class directional_smoothing_selection.

See Also

Other directional smoothing helpers: select_toroidal_smoothing()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
select_cyl_smoothing(
  dat$theta, dat$x,
  kappa_values = c(8, 12),
  h_values = c(0.3, 0.5),
  n_folds = 2,
  seed = 1
)

Select smoothing parameters for toroidal conditional density

Description

Ranks candidate smoothing parameters by K-fold conditional log-likelihood for f(phi | theta).

Usage

select_toroidal_smoothing(
  theta,
  phi,
  kappa_theta_values = c(6, 8, 12, 16, 24, 36),
  kappa_phi_values = kappa_theta_values,
  n_folds = 5,
  seed = NULL
)

Arguments

theta

Conditioning angles in radians.

phi

Response angles in radians.

kappa_theta_values

Candidate concentrations for the conditioning angle.

kappa_phi_values

Candidate concentrations for the response angle.

n_folds

Number of cross-validation folds.

seed

Optional random seed for fold assignment.

Value

A data frame ranked by decreasing mean held-out log score. The returned object has class directional_smoothing_selection.

See Also

Other directional smoothing helpers: select_cyl_smoothing()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
select_toroidal_smoothing(
  dat$theta, dat$phi,
  kappa_theta_values = c(8, 12),
  kappa_phi_values = c(8, 12),
  n_folds = 2,
  seed = 1
)

Evaluate sensitivity to smoothing concentration

Description

Evaluate sensitivity to smoothing concentration

Usage

sensitivity_bandwidth_grid(
  theta,
  target,
  space = c("cylindrical", "toroidal"),
  kappa_values = c(8, 12, 20, 32)
)

Arguments

theta

Conditioning angle in radians.

target

Real-valued response or second angle.

space

Either "cylindrical" or "toroidal".

kappa_values

Numeric vector of candidate concentrations.

Value

A data frame of compact sensitivity summaries.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), marginal_support_data(), plot_marginal_support(), simulate_independence_lineup()

Examples

dat <- simulate_cylindrical(n = 60, seed = 1)
sensitivity_bandwidth_grid(dat$theta, dat$x, space = "cylindrical", kappa_values = c(8, 12))

Simulate diagnostic circular-linear data

Description

Simulate diagnostic circular-linear data

Usage

simulate_cyl_diagnostic(
  n = 800,
  scenario = c("independent", "smooth", "heteroscedastic", "multimodal", "seam"),
  seed = NULL
)

Arguments

n

Number of observations.

scenario

Diagnostic scenario.

seed

Optional random seed.

Value

A data frame with theta, x and scenario.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_atlas_data(), diagnostic_scenarios(), plot_classical_comparison(), plot_diagnostic_atlas(), simulate_tor_diagnostic()

Examples

simulate_cyl_diagnostic(n = 40, scenario = "smooth", seed = 1)

Simulate circular-linear data

Description

Simulates examples on the cylinder, where theta is an angle in radians and x is a real-valued response.

Usage

simulate_cylindrical(
  n = 500,
  scenario = c("nonlinear", "independent", "unimodal", "heteroscedastic", "multimodal"),
  seed = NULL
)

Arguments

n

Number of observations.

scenario

Dependence pattern to simulate.

seed

Optional random seed.

Value

A data frame with columns theta, x and scenario.

See Also

Other directional simulation helpers: simulate_toroidal()

Examples

simulate_cylindrical(n = 30, scenario = "nonlinear", seed = 1)

Simulate a visual-inference lineup under independence

Description

Simulate a visual-inference lineup under independence

Usage

simulate_independence_lineup(
  data,
  plot_fun = NULL,
  m = 20,
  seed = NULL,
  space = c("cylindrical", "toroidal"),
  ...
)

Arguments

data

Data frame containing theta and either x or phi.

plot_fun

Optional function taking one data frame and returning a ggplot object.

m

Number of lineup panels.

seed

Optional random seed.

space

Either "cylindrical" or "toroidal".

...

Passed to the default plot function when plot_fun is NULL.

Value

A list with plots, true position and metadata. The returned object has class directional_lineup.

See Also

Other directional uncertainty helpers: autoplot.bootstrap_stat_orbit(), autoplot.bootstrap_toroidal_ridge(), bootstrap_stat_orbit(), bootstrap_toroidal_ridge(), marginal_support_data(), plot_marginal_support(), sensitivity_bandwidth_grid()

Examples

dat <- simulate_cyl_diagnostic(n = 40, scenario = "smooth", seed = 1)
lineup <- simulate_independence_lineup(
  dat,
  plot_fun = function(d) ggplot2::ggplot(d, ggplot2::aes(theta, x)) + ggplot2::geom_point(),
  m = 4,
  seed = 1,
  space = "cylindrical"
)
length(lineup$plots)

Simulate diagnostic circular-circular data

Description

Simulate diagnostic circular-circular data

Usage

simulate_tor_diagnostic(
  n = 900,
  scenario = c("independent_concentrated", "diagonal", "doubling", "bifurcation",
    "uniform_marginal_dependence"),
  seed = NULL
)

Arguments

n

Number of observations.

scenario

Diagnostic scenario.

seed

Optional random seed.

Value

A data frame with theta, phi and scenario.

See Also

Other directional diagnostics: autoplot.diagnostic_atlas_data(), diagnostic_atlas_data(), diagnostic_scenarios(), plot_classical_comparison(), plot_diagnostic_atlas(), simulate_cyl_diagnostic()

Examples

simulate_tor_diagnostic(n = 40, scenario = "diagonal", seed = 1)

Simulate circular-circular data

Description

Simulates examples on the torus, where both theta and phi are angles in radians.

Usage

simulate_toroidal(
  n = 500,
  scenario = c("nonlinear", "diagonal", "anti_diagonal", "multimodal", "independent"),
  seed = NULL
)

Arguments

n

Number of observations.

scenario

Dependence pattern to simulate.

seed

Optional random seed.

Value

A data frame with columns theta, phi and scenario.

See Also

Other directional simulation helpers: simulate_cylindrical()

Examples

simulate_toroidal(n = 30, scenario = "diagonal", seed = 1)

Summarize spherical directions

Description

Computes the mean direction vector and mean spherical coordinates.

Usage

spherical_summary(
  theta,
  phi,
  weights = NULL,
  convention = c("azimuth_colatitude", "azimuth_elevation"),
  na.rm = TRUE
)

Arguments

theta

Azimuth angle in radians.

phi

Colatitude or elevation angle in radians.

weights

Optional non-negative weights.

convention

Interpretation of phi.

na.rm

Should missing values be removed?

Value

A tibble with sample size, mean spherical coordinates and resultant length.

See Also

Other spherical helpers: cartesian_to_spherical(), spherical_to_cartesian()


Convert spherical coordinates to Cartesian coordinates

Description

Convert spherical coordinates to Cartesian coordinates

Usage

spherical_to_cartesian(
  theta,
  phi,
  radius = 1,
  convention = c("azimuth_colatitude", "azimuth_elevation")
)

Arguments

theta

Azimuth angle in radians.

phi

Colatitude or elevation angle in radians.

radius

Radius.

convention

Interpretation of phi.

Value

A tibble with x, y and z.

See Also

Other spherical helpers: cartesian_to_spherical(), spherical_summary()


Circular density statistic

Description

Estimates a smooth circular density using a von Mises kernel. The density wraps around the origin, avoiding the boundary artifacts of a linear kernel density estimate. When bw is not supplied, the concentration is chosen from a simple resultant-length heuristic; it should be treated as an exploratory smoothing choice rather than an inferential bandwidth selector.

Usage

stat_circular_density(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  method = c("kernel", "vonmises"),
  bw = NULL,
  adjust = 1,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

method

Density method. Currently "kernel" and "vonmises" both use a von Mises kernel estimator.

bw

Optional circular bandwidth. It is interpreted as 1 / sqrt(kappa).

adjust

Multiplicative adjustment applied to bw or to the automatic bandwidth scale.

n

Number of grid points.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer. Computed variables are x, density, scaled, count, n, bw and kappa.

See Also

Other circular density layers: geom_circular_density()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  stat_circular_density()

Annotate circular tests

Description

Adds a text annotation with the p-value from a Rayleigh or Watson-Williams test.

Usage

stat_circular_test(
  mapping = NULL,
  data = NULL,
  geom = "text",
  position = "identity",
  ...,
  test = c("rayleigh", "watson_williams"),
  x = 0,
  y = 1,
  digits = 3,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the text geom.

test

Test to compute.

x, y

Text position.

digits

Number of digits used for p-value formatting.

na.rm

Should missing values be removed?

Value

A ggplot2 layer.

See Also

Other circular tests: rayleigh_test(), watson_williams_test()


Add a circular topography stat layer

Description

Estimates a circular-linear density and returns grid values for topographic displays. Use with aes(x = theta, y = response).

Usage

stat_circular_topography(
  mapping = NULL,
  data = NULL,
  geom = "tile",
  position = "identity",
  n_theta = 181,
  n_x = 200,
  kappa = 20,
  h = NULL,
  conditional = TRUE,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_theta

Number of angular grid points.

n_x

Number of linear grid points.

kappa

Circular concentration for the conditioning kernel.

h

Linear bandwidth. If NULL, a rule-of-thumb bandwidth is used.

conditional

If TRUE, estimate f(y | x_angle).

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other cylindrical dependence layers: geom_phase_loom(), stat_statistical_orbit(), stat_statistical_orbit_ribbon()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = x)) +
  stat_circular_topography(n_theta = 24, n_x = 30)

Mean direction statistic

Description

Computes one mean direction per group, with resultant length and an optional approximate confidence arc.

Usage

stat_mean_direction(
  mapping = NULL,
  data = NULL,
  geom = "segment",
  position = "identity",
  ...,
  length = c("resultant", "fixed"),
  radius = NULL,
  conf.int = FALSE,
  level = 0.95,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

length

Should the displayed segment length be proportional to the mean resultant length ("resultant") or fixed ("fixed")?

radius

Optional maximum displayed radius.

conf.int

Should approximate confidence limits be computed?

level

Confidence level used when conf.int = TRUE.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer. Computed variables include x, xend, y, yend, mean, R, Rbar, n, kappa, ci_low and ci_high.

See Also

Other mean direction layers: geom_mean_direction()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  stat_mean_direction()

Compute statistical orbit data

Description

Computes local conditional means, local standard deviations and local skewness over an angular grid.

Usage

stat_orbit_data(theta, x, n_theta = 181, kappa = 20)

Arguments

theta

Angles in radians.

x

Real-valued response.

n_theta

Number of angular grid points.

kappa

Circular concentration for local weighting.

Value

A data frame with theta, mu, lower, upper and skew.

See Also

Other cylindrical dependence helpers: circular_topography_data(), estimate_cyl_density(), phase_loom_data()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
stat_orbit_data(dat$theta, dat$x, n_theta = 24)

Rose diagram statistic

Description

Bins circular angles over a full period and returns counts, densities and proportions for rose diagrams.

Usage

stat_rose(
  mapping = NULL,
  data = NULL,
  geom = "col",
  position = "identity",
  ...,
  bins = 30,
  binwidth = NULL,
  boundary = 0,
  closed = TRUE,
  area = FALSE,
  normalize = c("count", "density", "proportion"),
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

bins

Number of bins over the circular period.

binwidth

Optional bin width in radians. If supplied, bins is ignored after the number of bins is inferred from the period.

boundary

Lower boundary for the first bin.

closed

Included for API compatibility. Values on the upper period boundary are wrapped into the first bin.

area

If TRUE, radial heights are square-root transformed so that visual area is closer to the selected frequency scale.

normalize

Which scale should be used for the computed radial y value: counts, densities or proportions.

axial

Should angles be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer. Computed variables are xmin, xmax, x, count, density, proportion, width and y.

See Also

Other rose diagram layers: geom_rose()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  stat_rose(bins = 16) +
  coord_circular()

Add a statistical orbit line

Description

Add a statistical orbit line

Usage

stat_statistical_orbit(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  n_theta = 181,
  kappa = 20,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_theta

Number of angular grid points.

kappa

Circular concentration for local weighting.

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other cylindrical dependence layers: geom_phase_loom(), stat_circular_topography(), stat_statistical_orbit_ribbon()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = x)) +
  stat_statistical_orbit(n_theta = 24)

Add a statistical orbit ribbon

Description

Add a statistical orbit ribbon

Usage

stat_statistical_orbit_ribbon(
  mapping = NULL,
  data = NULL,
  geom = "ribbon",
  position = "identity",
  n_theta = 181,
  kappa = 20,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_theta

Number of angular grid points.

kappa

Circular concentration for local weighting.

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other cylindrical dependence layers: geom_phase_loom(), stat_circular_topography(), stat_statistical_orbit()

Examples

dat <- simulate_cylindrical(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = x)) +
  stat_statistical_orbit_ribbon(n_theta = 24, alpha = 0.2) +
  stat_statistical_orbit(n_theta = 24)

Add a conditional ridge stat layer on the torus

Description

Adds a conditional modal ridge for circular-circular data. Use with aes(x = theta, y = phi).

Usage

stat_toroidal_ridge(
  mapping = NULL,
  data = NULL,
  geom = "path",
  position = "identity",
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  tie_tolerance = 0.01,
  signed = TRUE,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

tie_tolerance

Relative tolerance used to flag near-tied distinct local modes without changing the selected ridge.

signed

If TRUE, plot angles in the signed interval.

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other toroidal dependence layers: geom_toroidal_flow(), stat_toroidal_topography()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = phi)) +
  stat_toroidal_ridge(n_theta = 24, n_phi = 24)

Add a toroidal topography stat layer

Description

Estimates a circular-circular density and returns grid values for topographic displays. Use with aes(x = theta, y = phi).

Usage

stat_toroidal_topography(
  mapping = NULL,
  data = NULL,
  geom = "tile",
  position = "identity",
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  conditional = FALSE,
  signed = TRUE,
  ...,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

conditional

If TRUE, estimate f(phi | theta).

signed

If TRUE, plot angles in the signed interval.

...

Additional arguments passed to the geom.

Value

A ggplot2 layer.

See Also

Other toroidal dependence layers: geom_toroidal_flow(), stat_toroidal_ridge()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
ggplot2::ggplot(dat, ggplot2::aes(x = theta, y = phi)) +
  stat_toroidal_topography(n_theta = 24, n_phi = 24)

Theoretical von Mises density

Description

Adds a theoretical von Mises density to a circular plot.

Usage

stat_vonmises(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  mu = 0,
  kappa = 1,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE
)

stat_wrapped_normal(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  mu = 0,
  sigma = 1,
  terms = 5,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE
)

stat_uniform_circular(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = FALSE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

mu

Mean direction in radians.

kappa

Non-negative concentration parameter.

n

Number of grid points.

axial

Should the density be drawn over an axial period of pi?

na.rm

Included for ggplot2 layer compatibility.

sigma

Standard deviation of the wrapped normal distribution.

terms

Number of wrapping terms on each side of the origin.

Value

A ggplot2 layer.

See Also

Other circular distributions: fit_vonmises_mixture(), stat_vonmises_fit(), stat_vonmises_mixture()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) +
  stat_vonmises(mu = pi / 2, kappa = 3)

Fitted von Mises density

Description

Estimates mu with mean_direction() and kappa with estimate_kappa(), then draws the fitted von Mises density.

Usage

stat_vonmises_fit(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

n

Number of grid points.

axial

Should the data be treated as axial, modulo pi?

na.rm

Should missing values be silently removed?

Value

A ggplot2 layer.

See Also

Other circular distributions: fit_vonmises_mixture(), stat_vonmises(), stat_vonmises_mixture()

Examples

ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) +
  geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) +
  stat_vonmises_fit()

Von Mises mixture density layer

Description

Fits or draws a mixture of von Mises densities.

Usage

stat_vonmises_mixture(
  mapping = NULL,
  data = NULL,
  geom = "line",
  position = "identity",
  ...,
  fit = NULL,
  k = 2,
  nstart = 1,
  seed = NULL,
  kappa_max = 10000,
  n = 512,
  axial = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping, data, geom, position, show.legend, inherit.aes

Standard ggplot2 layer arguments.

...

Additional arguments passed to the layer.

fit

Optional ggcircular_vonmises_mixture object. If NULL, the mixture is fitted to the layer's x aesthetic.

k

Number of components when fitting inside the statistic.

nstart

Number of EM starts when fitting inside the statistic.

seed

Optional random seed when fitting inside the statistic.

kappa_max

Maximum fitted concentration when fitting inside the statistic.

n

Number of grid points.

axial

Should data be treated as axial, modulo pi?

na.rm

Should missing values be removed before fitting?

Value

A ggplot2 layer.

See Also

Other circular distributions: fit_vonmises_mixture(), stat_vonmises(), stat_vonmises_fit()


Summarize circular posterior draws

Description

Summarize circular posterior draws

Usage

summarise_circular_draws(
  draws,
  variables = NULL,
  level = 0.95,
  axial = FALSE,
  ...
)

Arguments

draws

Circular draws from as_circular_draws() or any object accepted by posterior::as_draws_df().

variables

Optional variables to summarize.

level

Credible interval level.

axial

Should draws be treated as axial, modulo pi?

...

Additional arguments passed to as_circular_draws() when needed.

Value

A tibble with posterior circular summaries.

See Also

Other posterior helpers: as_circular_draws(), autoplot_circular_draws()


Circular plot themes

Description

Lightweight themes for circular plots. They keep a restrained grid and avoid imposing a strong visual identity.

Usage

theme_circular(base_size = 12, base_family = "")

theme_rose(base_size = 12, base_family = "")

theme_compass(base_size = 12, base_family = "")

Arguments

base_size

Base font size.

base_family

Base font family.

Value

A ggplot2 theme.

Examples

theme_circular()

Compute toroidal flow data

Description

Discretizes two angular variables into sectors and estimates joint or conditional mass flows between sectors.

Usage

toroidal_flow_data(
  theta,
  phi,
  n_sectors = 32,
  min_mass = 0.002,
  mass_type = c("joint", "conditional")
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_sectors

Number of sectors for both angles.

min_mass

Minimum mass to retain.

mass_type

Either "joint" for joint masses or "conditional" for masses normalized within each theta sector.

Value

A data frame with sector identifiers, endpoints and mass values.

See Also

Other toroidal dependence helpers: estimate_toroidal_density(), toroidal_ridge_data(), toroidal_topography_data()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
toroidal_flow_data(dat$theta, dat$phi, n_sectors = 12)

Compute a conditional toroidal ridge

Description

Extracts the modal phi value along a grid of conditioning angles and attaches the local circular concentration.

Usage

toroidal_ridge_data(
  theta,
  phi,
  n_theta = 181,
  n_phi = 181,
  kappa_theta = 20,
  kappa_phi = 20,
  tie_tolerance = 0.01
)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

n_theta

Number of theta grid points.

n_phi

Number of phi grid points.

kappa_theta

Kernel concentration for theta.

kappa_phi

Kernel concentration for phi.

tie_tolerance

Relative tolerance used to flag two distinct local maxima as near-tied. The selected ridge remains the first exact grid maximum for backward compatibility.

Value

A data frame with columns theta, phi, rho, ridge_group, n_local_modes, secondary_mode_ratio and ridge_ambiguous.

See Also

Other toroidal dependence helpers: estimate_toroidal_density(), toroidal_flow_data(), toroidal_topography_data()

Examples

dat <- simulate_toroidal(n = 80, scenario = "diagonal", seed = 1)
toroidal_ridge_data(dat$theta, dat$phi, n_theta = 24, n_phi = 24)

Compute toroidal topography data

Description

Compute toroidal topography data

Usage

toroidal_topography_data(theta, phi, conditional = FALSE, ...)

Arguments

theta

First angle in radians.

phi

Second angle in radians.

conditional

If TRUE, rows are normalized to estimate f(phi | theta).

...

Additional arguments passed to estimate_toroidal_density().

Value

A data frame with columns theta, phi and density.

See Also

Other toroidal dependence helpers: estimate_toroidal_density(), toroidal_flow_data(), toroidal_ridge_data()

Examples

dat <- simulate_toroidal(n = 80, seed = 1)
toroidal_topography_data(dat$theta, dat$phi, n_theta = 24, n_phi = 24)

Watson-Williams test for equal circular means

Description

Wrapper around circular::watson.williams.test() with explicit optional dependency handling. The Watson-Williams test assumes von Mises-like groups with comparable concentrations and should be used cautiously for small samples or weakly concentrated data.

Usage

watson_williams_test(x, group, ...)

Arguments

x

Numeric vector of angles in radians.

group

Grouping variable.

...

Additional arguments passed to circular::watson.williams.test().

Value

An object returned by circular::watson.williams.test().

See Also

Other circular tests: rayleigh_test(), stat_circular_test()


Simulated wind directions

Description

A reproducible simulated dataset of wind directions with station, speed and season variables. Angles are stored in radians.

Usage

wind_directions

Format

A tibble with 500 rows and 4 variables:

station

Station identifier.

direction

Wind direction in radians.

speed

Wind speed in arbitrary units.

season

Season label.

Source

Simulated for package examples.