| Title: | A 'ggplot2' Extension for Circular and Directional Data |
|---|---|
| Description: | Provides a 'ggplot2' grammar for circular, axial and directional data, including rose diagrams, circular densities, mean directions, confidence arcs, theoretical circular distributions and movement data visualizations. |
| Authors: | Aurélien Nicosia [aut, cre] |
| Maintainer: | Aurélien Nicosia <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-05 19:54:05 UTC |
| Source: | https://github.com/aureliennicosiaulaval/ggcircular |
Computes the signed difference x - y on a periodic scale. With the default
period, values are returned in [-pi, pi).
angular_difference(x, y, period = 2 * pi)angular_difference(x, y, period = 2 * pi)
x, y
|
Numeric vectors of angles. |
period |
Positive numeric period. |
A numeric vector following R recycling rules.
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()
angular_difference(0, 3 * pi / 2)angular_difference(0, 3 * pi / 2)
Computes the non-negative angular distance between x and y. With the
default period, values are returned in [0, pi].
angular_distance(x, y, period = 2 * pi)angular_distance(x, y, period = 2 * pi)
x, y
|
Numeric vectors of angles. |
period |
Positive numeric period. |
A non-negative numeric vector.
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()
angular_distance(0, 3 * pi / 2)angular_distance(0, 3 * pi / 2)
Simulated tracks for three individuals with derived step length, bearing and turn angle features.
animal_stepsanimal_steps
A tibble with 600 rows and 8 variables:
Animal identifier.
Step index.
Cartesian coordinates.
Euclidean step length.
Movement bearing in radians under the mathematical convention.
Signed turn angle in radians.
Latent movement state label.
Simulated for package examples.
Converts objects supported by posterior::as_draws_df() into a long tibble
of normalized angular draws.
as_circular_draws(draws, variables = NULL, period = 2 * pi, origin = 0)as_circular_draws(draws, variables = NULL, period = 2 * pi, origin = 0)
draws |
Posterior draws object. |
variables |
Optional variables to keep. |
period |
Angular period. |
origin |
Lower bound of the normalized interval. |
A tibble with draw identifiers, .variable and .angle.
Other posterior helpers:
autoplot_circular_draws(),
summarise_circular_draws()
Thin wrapper around mutate_directional_features() for pipelines where a
more explicit movement-data verb is useful.
as_step_data( data, x, y, id = NULL, time = NULL, angle_convention = c("mathematical", "bearing") )as_step_data( data, x, y, id = NULL, time = NULL, angle_convention = c("mathematical", "bearing") )
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 |
A tibble with movement features.
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()
Lightweight generics reserved for future integration with angular regression packages. The default methods fail with an explicit message rather than silently returning incomplete output.
augment_circular(x, ...) tidy_circular(x, ...) glance_circular(x, ...)augment_circular(x, ...) tidy_circular(x, ...) glance_circular(x, ...)
x |
A model or circular object. |
... |
Additional arguments passed to methods. |
Method-dependent tibble output.
Other circular model helpers:
circular_model_diagnostics(),
circular_residuals()
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.
augment_momentuHMM_angles( object, data = NULL, angle = NULL, state_method = c("viterbi", "stateProbs"), ... )augment_momentuHMM_angles( object, data = NULL, angle = NULL, state_method = c("viterbi", "stateProbs"), ... )
object |
A fitted |
data |
Optional data frame. If |
angle |
Optional name of the angle column. |
state_method |
State extraction method. |
... |
Reserved for future methods. |
A tibble with .angle, .state and optional state probabilities.
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()
Creates a quick diagnostic plot for a numeric vector of circular angles.
autoplot_circular( theta, bins = 24, density = TRUE, mean = TRUE, axial = FALSE, ... )autoplot_circular( theta, bins = 24, density = TRUE, mean = TRUE, axial = FALSE, ... )
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 |
... |
Additional arguments currently ignored. |
A ggplot object.
autoplot_circular(wind_directions$direction)autoplot_circular(wind_directions$direction)
Autoplot circular posterior draws
autoplot_circular_draws( draws, variables = NULL, type = c("density", "interval"), axial = FALSE, ... )autoplot_circular_draws( draws, variables = NULL, type = c("density", "interval"), axial = FALSE, ... )
draws |
Circular draws or posterior draws. |
variables |
Optional variables to plot. |
type |
Plot type. |
axial |
Should draws be treated as axial, modulo |
... |
Additional arguments passed to |
A ggplot object.
Other posterior helpers:
as_circular_draws(),
summarise_circular_draws()
Simulated axial orientation data, such as fiber or fault orientations, stored
modulo pi.
axial_orientationsaxial_orientations
A tibble with 300 rows and 3 variables:
Sample identifier.
Axial orientation in radians, modulo pi.
Group label.
Simulated for package examples.
Convert Cartesian coordinates to spherical coordinates
cartesian_to_spherical( x, y, z, convention = c("azimuth_colatitude", "azimuth_elevation") )cartesian_to_spherical( x, y, z, convention = c("azimuth_colatitude", "azimuth_elevation") )
x, y, z
|
Cartesian coordinates. |
convention |
Output convention for |
A tibble with theta, phi and radius.
Other spherical helpers:
spherical_summary(),
spherical_to_cartesian()
Check an angle vector
check_angle(x, allow_na = TRUE)check_angle(x, allow_na = TRUE)
x |
Object to check. |
allow_na |
Should missing values be allowed? |
Invisibly returns x if the check succeeds.
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()
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.
circular_mean_ci( x, level = 0.95, method = c("large_sample", "bootstrap"), R = 999, axial = FALSE, na.rm = TRUE, seed = NULL )circular_mean_ci( x, level = 0.95, method = c("large_sample", "bootstrap"), R = 999, axial = FALSE, na.rm = TRUE, seed = NULL )
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 |
na.rm |
Should missing values be removed? |
seed |
Optional random seed for the bootstrap. |
A tibble with mean, lower, upper, level, method, n and
Rbar.
Other circular summaries:
circular_sd(),
circular_summary(),
circular_variance(),
estimate_kappa(),
mean_direction(),
mean_resultant_length(),
resultant_length()
Summarizes circular residual diagnostics for supported angular model objects.
circular_model_diagnostics(object, data = NULL, ...)circular_model_diagnostics(object, data = NULL, ...)
object |
A supported angular model object. |
data |
Optional data frame to bind to the diagnostic columns. |
... |
Reserved for future methods. |
A tibble with residual mean direction, resultant length, circular variance and maximum absolute circular residual.
Other circular model helpers:
augment_circular(),
circular_residuals()
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.
circular_residuals(object, data = NULL, ...)circular_residuals(object, data = NULL, ...)
object |
A supported angular model object. |
data |
Optional data frame to bind to the diagnostic columns. |
... |
Reserved for future methods. |
A tibble with .observed, .fitted, .resid, .abs_resid,
.index and .model_class.
Other circular model helpers:
augment_circular(),
circular_model_diagnostics()
fit <- structure( list(y = c(0, 0.2, 0.4), mui = c(0.05, 0.15, 0.5)), class = "angular" ) circular_residuals(fit)fit <- structure( list(y = c(0, 0.2, 0.4), mui = c(0.05, 0.15, 0.5)), class = "angular" ) circular_residuals(fit)
Uses the common descriptive statistic sqrt(-2 * log(Rbar)).
circular_sd(x, axial = FALSE, na.rm = TRUE)circular_sd(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
Circular standard deviation in radians.
Other circular summaries:
circular_mean_ci(),
circular_summary(),
circular_variance(),
estimate_kappa(),
mean_direction(),
mean_resultant_length(),
resultant_length()
Computes grouped circular summaries for an angle column. Existing dplyr
groups are respected, and additional grouping variables can be supplied in
....
circular_summary(data, angle, ..., axial = FALSE, na.rm = TRUE)circular_summary(data, angle, ..., axial = FALSE, na.rm = TRUE)
data |
A data frame or tibble. |
angle |
Angle column, in radians. |
... |
Optional grouping variables. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
A tibble with columns n, mean, R, Rbar, variance, sd and
kappa. The returned object also has class ggcircular_summary.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_variance(),
estimate_kappa(),
mean_direction(),
mean_resultant_length(),
resultant_length()
tibble::tibble(group = c("a", "a", "b"), theta = c(0, pi / 2, pi)) |> dplyr::group_by(group) |> circular_summary(theta)tibble::tibble(group = c("a", "a", "b"), theta = c(0, pi / 2, pi)) |> dplyr::group_by(group) |> circular_summary(theta)
Circular variance
circular_variance(x, axial = FALSE, na.rm = TRUE)circular_variance(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
The circular variance 1 - Rbar.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_summary(),
estimate_kappa(),
mean_direction(),
mean_resultant_length(),
resultant_length()
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.
compass_to_rad(x)compass_to_rad(x)
x |
Character vector of compass labels. |
Numeric vector of bearing angles in radians.
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()
compass_to_rad(c("N", "E", "S", "W"))compass_to_rad(c("N", "E", "S", "W"))
Compute bearings
compute_bearing(x, y, angle_convention = c("mathematical", "bearing"))compute_bearing(x, y, angle_convention = c("mathematical", "bearing"))
x, y
|
Numeric coordinate vectors. |
angle_convention |
Angle convention. |
Numeric vector of bearings in radians. The first value is NA.
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
compute_step_length(x, y)compute_step_length(x, y)
x, y
|
Numeric coordinate vectors. |
Numeric vector of Euclidean step lengths. The first value is NA.
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
compute_turn_angle(bearing, period = 2 * pi)compute_turn_angle(bearing, period = 2 * pi)
bearing |
Numeric vector of bearings in radians. |
period |
Angular period. |
Numeric vector of signed turn angles. The first value is NA.
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()
Convenience wrapper around ggplot2::coord_polar() with arguments expressed
in circular-data language.
coord_circular( zero = c("east", "north", "west", "south"), direction = c("counterclockwise", "clockwise"), start = NULL, clip = "on" )coord_circular( zero = c("east", "north", "west", "south"), direction = c("counterclockwise", "clockwise"), start = NULL, clip = "on" )
zero |
Direction corresponding to angle zero. |
direction |
Direction in which angles increase. |
start |
Optional start offset in radians. If supplied, it overrides
|
clip |
Should drawing be clipped to the plot panel? |
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.
A ggplot2 coordinate object.
Other circular scales:
scale_x_circular_radians()
coord_circular() coord_circular(zero = "north", direction = "clockwise")coord_circular() coord_circular(zero = "north", direction = "clockwise")
Convert degrees to radians
deg_to_rad(x)deg_to_rad(x)
x |
Numeric vector in degrees. |
Numeric vector in radians.
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()
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.
estimate_kappa(x, axial = FALSE, na.rm = TRUE)estimate_kappa(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
Estimated concentration parameter kappa.
Fisher, N. I. (1993). Statistical Analysis of Circular Data. Cambridge University Press.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_summary(),
circular_variance(),
mean_direction(),
mean_resultant_length(),
resultant_length()
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.
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 )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 )
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 |
init |
Initialization method, either |
nstart |
Number of EM starts. The fit with the largest log-likelihood is retained. |
init_params |
Optional list or data frame with initial |
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. |
An object of class ggcircular_vonmises_mixture.
Other circular distributions:
stat_vonmises(),
stat_vonmises_fit(),
stat_vonmises_mixture()
fit <- fit_vonmises_mixture(wind_directions$direction, k = 2) tidy_circular(fit)fit <- fit_vonmises_mixture(wind_directions$direction, k = 2) tidy_circular(fit)
Draws a circular density estimate as a line. This is a convenience wrapper
around stat_circular_density().
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 )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 )
mapping, data, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
stat |
Statistical transformation, usually |
... |
Additional arguments passed to the layer. |
method |
Density method. Currently |
bw |
Optional circular bandwidth. It is interpreted as |
adjust |
Multiplicative adjustment applied to |
n |
Number of grid points. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer.
Other circular density layers:
stat_circular_density()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_circular_density()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_circular_density()
Convenience layers for plotting angular observations at a fixed radius.
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 )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 )
mapping, data, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
... |
Additional arguments passed to |
radius |
Radius at which points or rugs are drawn. |
na.rm |
Should missing values be silently removed? |
rug_length |
Radial length of rug marks. |
A ggplot2 layer.
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()
Draws angular intervals as arcs at a fixed radius. Intervals crossing zero are split into two path segments.
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 )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 )
mapping, data, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
... |
Additional arguments passed to the path geometry. |
radius |
Default radius used when no |
n |
Number of points used to discretize each interval. |
na.rm |
Should missing interval endpoints be silently removed? |
A ggplot2 layer.
tibble::tibble(lower = 5.5, upper = 0.5) |> ggplot2::ggplot(ggplot2::aes(xmin = lower, xmax = upper)) + geom_confidence_arc()tibble::tibble(lower = 5.5, upper = 0.5) |> ggplot2::ggplot(ggplot2::aes(xmin = lower, xmax = upper)) + geom_confidence_arc()
Draws directional arrows from Cartesian coordinates and an angle.
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 )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 )
mapping, data, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
... |
Additional arguments passed to |
length |
Default arrow length when no |
arrow_length |
Grid unit controlling the arrow head length. |
angle_convention |
Angle convention. |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer.
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()
ggplot2::ggplot(animal_steps, ggplot2::aes(x = x, y = y, angle = bearing)) + geom_direction_arrow()ggplot2::ggplot(animal_steps, ggplot2::aes(x = x, y = y, angle = bearing)) + geom_direction_arrow()
Draws a radial segment at the circular mean direction. The segment length can be fixed or proportional to the mean resultant length.
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 )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 )
mapping, data, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
stat |
Statistical transformation, usually |
... |
Additional arguments passed to the layer. |
length |
Should the displayed segment length be proportional to the mean
resultant length ( |
radius |
Optional maximum displayed radius. |
conf.int |
Should approximate confidence limits be computed? |
level |
Confidence level used when |
axial |
Should the data be treated as axial, modulo |
arrow |
Should a small arrow head be drawn? |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer.
Other mean direction layers:
stat_mean_direction()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(bins = 16) + geom_mean_direction()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(bins = 16) + geom_mean_direction()
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().
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 )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 )
mapping, data, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
stat |
Statistical transformation, usually |
... |
Additional arguments passed to the layer. |
bins |
Number of bins over the circular period. |
binwidth |
Optional bin width in radians. If supplied, |
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 |
normalize |
Which scale should be used for the computed radial |
axial |
Should angles be treated as axial, modulo |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer.
Other rose diagram layers:
stat_rose()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(bins = 16) + coord_circular()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(bins = 16) + coord_circular()
Convert hours to radians
hour_to_rad(x)hour_to_rad(x)
x |
Numeric vector in hours on a 24-hour clock. |
Numeric vector in radians.
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()
A reproducible simulated dataset of hourly activity converted to circular angles.
hourly_activityhourly_activity
A tibble with 240 rows and 5 variables:
Individual identifier.
Hour of day.
Hour converted to radians.
Activity level.
Group label.
Simulated for package examples.
Test whether an object can represent angles
is_angle(x)is_angle(x)
x |
Object to test. |
TRUE when x is numeric and contains only finite values or NA.
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()
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.
mean_direction(x, axial = FALSE, na.rm = TRUE)mean_direction(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
A single angle in radians, or NA_real_ when the mean is undefined.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_summary(),
circular_variance(),
estimate_kappa(),
mean_resultant_length(),
resultant_length()
mean_direction(c(0, pi / 4, pi / 2))mean_direction(c(0, pi / 4, pi / 2))
Mean resultant length
mean_resultant_length(x, axial = FALSE, na.rm = TRUE)mean_resultant_length(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
The mean resultant length Rbar, between 0 and 1 when defined.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_summary(),
circular_variance(),
estimate_kappa(),
mean_direction(),
resultant_length()
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.
mutate_directional_features( data, x, y, id = NULL, time = NULL, angle_convention = c("mathematical", "bearing") )mutate_directional_features( data, x, y, id = NULL, time = NULL, angle_convention = c("mathematical", "bearing") )
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 |
A tibble with added step_length, bearing and turn_angle.
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()
tibble::tibble(id = 1, time = 1:3, x = 0:2, y = 0) |> mutate_directional_features(x = x, y = y, id = id, time = time)tibble::tibble(id = 1, time = 1:3, x = 0:2, y = 0) |> mutate_directional_features(x = x, y = y, id = id, time = time)
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.
normalize_angle(x, period = 2 * pi, origin = 0)normalize_angle(x, period = 2 * pi, origin = 0)
x |
Numeric vector of angles. |
period |
Positive numeric period. Use |
origin |
Lower bound of the target interval. |
A numeric vector with the same length as x.
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()
normalize_angle(c(-pi, 0, 3 * pi))normalize_angle(c(-pi, 0, 3 * pi))
Convenience function for visualizing angles by observed or inferred states.
plot_state_angles( data, angle, state, type = c("rose", "density", "mean"), bins = 24, axial = FALSE )plot_state_angles( data, angle, state, type = c("rose", "density", "mean"), bins = 24, axial = FALSE )
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 |
A ggplot object.
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()
Converts angles to the nearest label among labels. Angles are interpreted
as bearings by default: zero is north and angles increase clockwise.
rad_to_compass(x, labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))rad_to_compass(x, labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))
x |
Numeric vector of angles in radians. |
labels |
Character vector of equally spaced labels. |
Character vector of labels.
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()
rad_to_compass(c(0, pi / 2, pi))rad_to_compass(c(0, pi / 2, pi))
Convert radians to degrees
rad_to_deg(x)rad_to_deg(x)
x |
Numeric vector in radians. |
Numeric vector in degrees.
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
rad_to_hour(x)rad_to_hour(x)
x |
Numeric vector in radians. |
Numeric vector in hours on a 24-hour clock.
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()
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.
rayleigh_test(x, axial = FALSE, na.rm = TRUE)rayleigh_test(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
An object of class htest.
Other circular tests:
stat_circular_test(),
watson_williams_test()
Resultant length
resultant_length(x, axial = FALSE, na.rm = TRUE)resultant_length(x, axial = FALSE, na.rm = TRUE)
x |
Numeric vector of angles in radians. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be removed? |
The sample resultant length R.
Other circular summaries:
circular_mean_ci(),
circular_sd(),
circular_summary(),
circular_variance(),
estimate_kappa(),
mean_direction(),
mean_resultant_length()
These scales label angular x axes in radians, degrees, hours or compass directions.
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), ... )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), ... )
breaks |
Break positions in radians. |
labels |
Break labels. |
limits |
Scale limits in radians. |
... |
Additional arguments passed to |
A ggplot2 scale.
Other circular scales:
coord_circular()
scale_x_circular_radians()scale_x_circular_radians()
Computes the mean direction vector and mean spherical coordinates.
spherical_summary( theta, phi, weights = NULL, convention = c("azimuth_colatitude", "azimuth_elevation"), na.rm = TRUE )spherical_summary( theta, phi, weights = NULL, convention = c("azimuth_colatitude", "azimuth_elevation"), na.rm = TRUE )
theta |
Azimuth angle in radians. |
phi |
Colatitude or elevation angle in radians. |
weights |
Optional non-negative weights. |
convention |
Interpretation of |
na.rm |
Should missing values be removed? |
A tibble with sample size, mean spherical coordinates and resultant length.
Other spherical helpers:
cartesian_to_spherical(),
spherical_to_cartesian()
Convert spherical coordinates to Cartesian coordinates
spherical_to_cartesian( theta, phi, radius = 1, convention = c("azimuth_colatitude", "azimuth_elevation") )spherical_to_cartesian( theta, phi, radius = 1, convention = c("azimuth_colatitude", "azimuth_elevation") )
theta |
Azimuth angle in radians. |
phi |
Colatitude or elevation angle in radians. |
radius |
Radius. |
convention |
Interpretation of |
A tibble with x, y and z.
Other spherical helpers:
cartesian_to_spherical(),
spherical_summary()
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.
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 )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 )
mapping, data, geom, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
... |
Additional arguments passed to the layer. |
method |
Density method. Currently |
bw |
Optional circular bandwidth. It is interpreted as |
adjust |
Multiplicative adjustment applied to |
n |
Number of grid points. |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer. Computed variables are x, density, scaled,
count, n, bw and kappa.
Other circular density layers:
geom_circular_density()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_circular_density()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_circular_density()
Adds a text annotation with the p-value from a Rayleigh or Watson-Williams test.
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 )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 )
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? |
A ggplot2 layer.
Other circular tests:
rayleigh_test(),
watson_williams_test()
Computes one mean direction per group, with resultant length and an optional approximate confidence arc.
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 )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 )
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 ( |
radius |
Optional maximum displayed radius. |
conf.int |
Should approximate confidence limits be computed? |
level |
Confidence level used when |
axial |
Should the data be treated as axial, modulo |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer. Computed variables include x, xend, y, yend,
mean, R, Rbar, n, kappa, ci_low and ci_high.
Other mean direction layers:
geom_mean_direction()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_mean_direction()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_mean_direction()
Bins circular angles over a full period and returns counts, densities and proportions for rose diagrams.
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 )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 )
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, |
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 |
normalize |
Which scale should be used for the computed radial |
axial |
Should angles be treated as axial, modulo |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer. Computed variables are xmin, xmax, x, count,
density, proportion, width and y.
Other rose diagram layers:
geom_rose()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_rose(bins = 16) + coord_circular()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + stat_rose(bins = 16) + coord_circular()
Adds a theoretical von Mises density to a circular plot.
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 )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 )
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 |
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. |
A ggplot2 layer.
Other circular distributions:
fit_vonmises_mixture(),
stat_vonmises_fit(),
stat_vonmises_mixture()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) + stat_vonmises(mu = pi / 2, kappa = 3)ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) + stat_vonmises(mu = pi / 2, kappa = 3)
Estimates mu with mean_direction() and kappa with estimate_kappa(),
then draws the fitted von Mises density.
stat_vonmises_fit( mapping = NULL, data = NULL, geom = "line", position = "identity", ..., n = 512, axial = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )stat_vonmises_fit( mapping = NULL, data = NULL, geom = "line", position = "identity", ..., n = 512, axial = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
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 |
na.rm |
Should missing values be silently removed? |
A ggplot2 layer.
Other circular distributions:
fit_vonmises_mixture(),
stat_vonmises(),
stat_vonmises_mixture()
ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) + stat_vonmises_fit()ggplot2::ggplot(wind_directions, ggplot2::aes(x = direction)) + geom_rose(ggplot2::aes(y = ggplot2::after_stat(density))) + stat_vonmises_fit()
Fits or draws a mixture of von Mises densities.
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 )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 )
mapping, data, geom, position, show.legend, inherit.aes
|
Standard ggplot2 layer arguments. |
... |
Additional arguments passed to the layer. |
fit |
Optional |
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 |
na.rm |
Should missing values be removed before fitting? |
A ggplot2 layer.
Other circular distributions:
fit_vonmises_mixture(),
stat_vonmises(),
stat_vonmises_fit()
Summarize circular posterior draws
summarise_circular_draws( draws, variables = NULL, level = 0.95, axial = FALSE, ... )summarise_circular_draws( draws, variables = NULL, level = 0.95, axial = FALSE, ... )
draws |
Circular draws from |
variables |
Optional variables to summarize. |
level |
Credible interval level. |
axial |
Should draws be treated as axial, modulo |
... |
Additional arguments passed to |
A tibble with posterior circular summaries.
Other posterior helpers:
as_circular_draws(),
autoplot_circular_draws()
Lightweight themes for circular plots. They keep a restrained grid and avoid imposing a strong visual identity.
theme_circular(base_size = 12, base_family = "") theme_rose(base_size = 12, base_family = "") theme_compass(base_size = 12, base_family = "")theme_circular(base_size = 12, base_family = "") theme_rose(base_size = 12, base_family = "") theme_compass(base_size = 12, base_family = "")
base_size |
Base font size. |
base_family |
Base font family. |
A ggplot2 theme.
theme_circular()theme_circular()
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.
watson_williams_test(x, group, ...)watson_williams_test(x, group, ...)
x |
Numeric vector of angles in radians. |
group |
Grouping variable. |
... |
Additional arguments passed to |
An object returned by circular::watson.williams.test().
Other circular tests:
rayleigh_test(),
stat_circular_test()
A reproducible simulated dataset of wind directions with station, speed and season variables. Angles are stored in radians.
wind_directionswind_directions
A tibble with 500 rows and 4 variables:
Station identifier.
Wind direction in radians.
Wind speed in arbitrary units.
Season label.
Simulated for package examples.