angle_correction {ggfields} | R Documentation |
Calculate correction for angle in the plot coordinate system
Description
The angle of a vector may be distorted when your plot uses a different
coordinate system than the one for which the angle is specified. If data
is a simple feature object (sf), the angle will be corrected
for the displayed coordinate reference system (crs). When
the crs is missing, an aspect ratio of 1 is assumed. For any other data,
the angle is corrected for the aspect ratio in the plot.
Usage
angle_correction(data, panel_params, coord)
Arguments
data |
fortified data used in a |
panel_params |
panel parameters as returned by GeomFields$setup_params() |
coord |
A coord object. |
Details
This function is used by default by geom_fields()
. For more details on
why this correction is required and how to customize corrections please see
vignette("angle_correction")
.
Value
A data.frame
with an additional angle_correction
column. The corrected angle is given
by angle_correction + angle
.
Author(s)
Pepijn de Vries
Examples
if (requireNamespace("ggplot2") && requireNamespace("stars")) {
library(ggplot2)
library(stars)
ggplot() +
geom_fields(
data = seawatervelocity,
mapping = aes(radius = as.numeric(v),
angle = as.numeric(angle),
col = as.numeric(v)),
## You can provide the `angle_correction()` as argument explicitly
## (it is already the default). Note that the plotted region requires
## hardly any correction for the angles.
.angle_correction = angle_correction)
}