View source: R/geom_arrow_segment.R
| geom_arrow_segment | R Documentation |
geom_arrow_segment() draws a straight arrow between points (x, y) and
(xend, yend). In contrast to geom_segment(), the xend and yend
aesthetics default to x and y respectively, so only one of xend and
yend is required.
geom_arrow_segment(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
arrow_head = arrow_head_wings(),
arrow_fins = NULL,
arrow_mid = NULL,
length = 4,
length_head = NULL,
length_fins = NULL,
length_mid = NULL,
justify = 0,
force_arrow = FALSE,
mid_place = 0.5,
resect = 0,
resect_head = NULL,
resect_fins = NULL,
lineend = "butt",
linejoin = "round",
linemitre = 10,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
arrow_head, arrow_fins, arrow_mid |
A function call to one of the arrow ornament functions that can determine the shape of the arrow head, fins or middle (interior) arrows. |
length, length_head, length_fins, length_mid |
Determines the size of
the arrow ornaments.
|
justify |
A |
force_arrow |
A |
mid_place |
Sets the location of middle (interior) arrows, when applicable. Can be one of the following:
|
resect, resect_head, resect_fins |
A |
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
linemitre |
Line mitre limit (number greater than 1). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
A <Layer> ggproto object that can be added to a plot.
geom_arrow_segment() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | x | |
| • | y | |
| • | xend or yend | |
| • | alpha | → NA |
| • | arrow_fins | → NULL |
| • | arrow_head | → NULL |
| • | arrow_mid | → NULL |
| • | colour | → via theme() |
| • | group | → inferred |
| • | linetype | → via theme() |
| • | linewidth | → via theme() |
| • | linewidth_fins | → NULL |
| • | linewidth_head | → NULL |
| • | resect_fins | → NULL |
| • | resect_head | → NULL |
| • | stroke_colour | → via theme() |
| • | stroke_width | → via theme() |
The linewidth_fins and linewidth_head inherit from linewidth. They can be used to seperately control the start- and end-width.
Learn more about setting these aesthetics in vignette("ggplot2-specs").
Other arrow geoms:
annotate_arrow(),
geom_arrow(),
geom_arrow_chain(),
geom_arrow_curve()
# Setup dummy data
set.seed(42)
df <- data.frame(
x = LETTERS[1:6],
y = 6:1 + rnorm(6)
)
# We can omit either `xend` or `yend` for this segment geom
p <- ggplot(df, aes(x, y = 0, yend = y, colour = x))
p + geom_arrow_segment()
# We can set the linewidth globally
p + geom_arrow_segment(aes(linewidth = y))
# Or seperately for the head and fins
p + geom_arrow_segment(aes(linewidth_head = y, linewidth_fins = 0))
# We can also place arrows in the middle
p + geom_arrow_segment(
arrow_mid = arrow_head_line(), mid_place = c(0.33, 0.66),
arrow_head = NULL # Turn off head
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.