View source: R/geom_textabline.R
geom_textabline | R Documentation |
These geoms add labelled reference lines to a plot, either
horizontal, vertical, or diagonal (specified by slope and intercept).
These are useful for annotating plots. They are the labelled equivalent of
the geom_vline
, geom_hline
and geom_abline
from ggplot2.
geom_textabline(
mapping = NULL,
data = NULL,
slope,
intercept,
...,
na.rm = FALSE,
show.legend = NA
)
geom_labelabline(
mapping = NULL,
data = NULL,
slope,
intercept,
...,
straight = NULL,
label.r = unit(0.15, "lines"),
label.padding = unit(0.25, "lines"),
na.rm = FALSE,
show.legend = NA
)
geom_texthline(
mapping = NULL,
data = NULL,
yintercept,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_labelhline(
mapping = NULL,
data = NULL,
yintercept,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
straight = NULL,
label.r = unit(0.15, "lines"),
label.padding = unit(0.25, "lines")
)
geom_textvline(
mapping = NULL,
data = NULL,
xintercept,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_labelvline(
mapping = NULL,
data = NULL,
xintercept,
stat = "identity",
position = "identity",
...,
arrow = NULL,
lineend = "butt",
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 |
slope |
The slope of the abline |
intercept |
the point on the y axis at which the abline crosses it. |
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
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. |
yintercept |
The value at which the line should intercept the y axis |
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. |
arrow |
Arrow specification, as created by |
lineend |
Line end style (round, butt, square). |
inherit.aes |
If |
xintercept |
The value at which the line should intercept the y axis |
Although reference lines are straight, and therefore don't lend themselves to curved text, these geom layers are included in this package because they make labelling reference lines easier, allow automatic line breaking if desired, and will translate nicely into polar co-ordinates.
These geoms act slightly differently from other geoms. You can supply the
parameters in two ways: either as arguments to the layer function,
or via aesthetics. If you use arguments, e.g.
geom_textabline(label = "my label", intercept = 0, slope = 1)
, then behind
the scenes the geom makes a new data frame containing just the data you've
supplied. That means that the lines will be the same in all facets; if you
want them to vary across facets, construct the data frame yourself and use
aesthetics.
Unlike most other geoms, these geoms do not inherit aesthetics from the plot default, because they do not understand x and y aesthetics which are commonly set in the plot. They also do not affect the x and y scales.
A Layer
ggproto object that can be added to a plot.
The geom_textabline()
, geom_texthline()
and geom_textvline()
understand
the following aesthetics (required aesthetics are in bold):
label
slope
(geom_textabline()
and geom_labelabline()
)
intercept
(geom_textabline()
and
geom_labelabline()
)
yintercept
(geom_texthline()
and
geom_labelhline()
)
xintercept
(geom_textvline()
and
geom_labelvline()
)
alpha
angle
colour
family
fontface
group
hjust
vjust
linecolour
lineheight
linetype
linewidth
size
spacing
textcolour
In addition to aforementioned aesthetics, geom_labelabline()
,
geom_labelhline()
and geom_labelvline()
also understand:
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.
Other geom layers that place text on paths.
ggplot(mtcars, aes(mpg, disp)) +
geom_point() +
geom_texthline(yintercept = 200, label = "displacement threshold",
hjust = 0.8, color = "red4") +
geom_textvline(xintercept = 20, label = "consumption threshold", hjust = 0.8,
linetype = 2, vjust = 1.3, color = "blue4") +
geom_textabline(slope = 15, intercept = -100, label = "partition line",
color = "green4", hjust = 0.6, vjust = -0.2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.