annotation_fields {ggfields} | R Documentation |
Annotate a ggplot with vector fields
Description
Functions exactly the same as geom_fields()
, with that difference
that this function does not train the x
and y
scales. This
makes the data central, and uses this layer to support it. Consequently,
annotation_fields()
does not accept a stat
argument.
Usage
annotation_fields(
mapping = NULL,
data = NULL,
position = "identity",
na.rm = FALSE,
show.legend = NA,
max_radius = ggplot2::unit(0.5, "cm"),
.angle_correction = angle_correction,
arrow = grid::arrow(length = ggplot2::unit(0.2, "cm")),
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
Can be one of four things:
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
max_radius |
Maximum radius to which the |
.angle_correction |
Function to correct the angle in the aesthetics for the projection and/or
aspect ratio used in the plot. When set to |
arrow |
specification for arrow heads, as created by |
inherit.aes |
If |
... |
Other arguments passed on to |
Value
Author(s)
Pepijn de Vries
Examples
if (requireNamespace("stars") && requireNamespace("ggplot2")) {
library(stars)
library(ggplot2)
data("seawatervelocity")
sw_sub <- seawatervelocity[,8:13,1:5]
## Note that the `seawatervelocity` spans a much larger area,
## but the plot only focuses on `sw_sub`
ggplot() +
geom_stars(data = sw_sub) +
annotation_fields(data = seawatervelocity,
aes(angle = as.numeric(atan2(vo, uo)),
radius = as.numeric(pythagoras(uo, vo)))) +
labs(radius = "v [m/s]")
}