View source: R/geom_textsegment.R
geom_textsegment | R Documentation |
geom_textsegment
draws a line between two points defined by (x, y) and
(xend, yend) and places a text label on that line. It is the text-placement
equivalent of geom_segment()
.
geom_textsegment(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
linejoin = "round",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
straight = NULL
)
geom_labelsegment(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
linejoin = "round",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
straight = NULL,
label.r = unit(0.15, "lines"),
label.padding = unit(0.25, "lines")
)
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, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to
|
arrow |
Arrow specification, as created by |
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
straight |
A |
label.r |
Radius of rounded corners. Defaults to 0.15 lines. |
label.padding |
Amount of padding around label. Defaults to 0.25 lines. |
A Layer
ggproto object that can be added to a plot.
geom_textsegment()
understands the following aesthetics (required aesthetics are in bold):
x
y
xend
yend
label
alpha
angle
colour
family
fontface
group
hjust
linecolour
lineheight
linetype
linewidth
size
spacing
textcolour
vjust
In addition to aforementioned aesthetics, geom_labelsegment()
also understands:
boxcolour
boxlinetype
boxlinewidth
fill
The spacing
aesthetic allows fine control of spacing
of text, which is called 'tracking' in typography.
The default is 0 and units are measured in 1/1000 em.
Numbers greater than zero increase the spacing,
whereas negative numbers decrease the spacing.
Learn more about setting these aesthetics
in vignette("ggplot2-specs")
.
Other geom layers that place text on paths.
# The convenience here is that the position and angle
# are in sync automatically with the data
sleep2 <- reshape(sleep, direction = "wide",
idvar = "ID", timevar = "group")
ggplot(sleep2, aes(x = "Drug 1", y = extra.1)) +
geom_textsegment(
aes(xend = "Drug 2", yend = extra.2,
label = paste0("Patient #", ID))
)
# As an annotation
ggplot(mapping = aes(x, y)) +
geom_col(
data = data.frame(x = c(1, 2), y = c(1, 10))
) +
annotate(
"textsegment",
x = 1, xend = 2, y = 1, yend = 10,
label = "10x increase", arrow = arrow()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.