Binding for geomtextpath::geom_textsf()
and
geomtextpath::geom_labelsf()
Usage
geom_cnt_text(
mapping = ggplot2::aes(),
data = NULL,
stat = "sf",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
keep = 0.5,
method = c("voronoi", "straight"),
simplify = TRUE,
...
)
geom_cnt_label(
mapping = ggplot2::aes(),
data = NULL,
stat = "sf",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
keep = 0.5,
method = c("voronoi", "straight"),
simplify = TRUE,
...
)
Arguments
- mapping
Set of aesthetic mappings created by
aes()
. If specified andinherit.aes = TRUE
(the default), it is combined with the default mapping at the top level of the plot. You must supplymapping
if there is no plot mapping.- data
The data to be displayed in this layer. There are three options:
If
NULL
, the default, the data is inherited from the plot data as specified in the call toggplot()
.A
data.frame
, or other object, will override the plot data. All objects will be fortified to produce a data frame. Seefortify()
for which variables will be created.A
function
will be called with a single argument, the plot data. The return value must be adata.frame
, and will be used as the layer data. Afunction
can be created from aformula
(e.g.~ head(.x, 10)
).- stat
The statistical transformation to use on the data for this layer, either as a
ggproto
Geom
subclass or as a string naming the stat stripped of thestat_
prefix (e.g."count"
rather than"stat_count"
)- position
Position adjustment, either as a string naming the adjustment (e.g.
"jitter"
to useposition_jitter
), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.- na.rm
If
FALSE
, the default, missing values are removed with a warning. IfTRUE
, missing values are silently removed.- show.legend
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.FALSE
never includes, andTRUE
always includes.You can also set this to one of "polygon", "line", and "point" to override the default legend.
- inherit.aes
If
FALSE
, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g.borders()
.- keep
numeric, proportion of points to retain (0.05-5.0; default 0.5). See Details.
- method
character, either
"voronoi"
(default) or"straight"
, or just the first letter"v"
or"s"
. See Details.- simplify
logical, if
TRUE
(default) then the centerline will be smoothed withsmoothr::smooth_ksmooth()
- ...
Arguments passed on to
geom_textpath
,geom_labelpath
text_only
A
logical(1)
indicating whether the path part should be plotted along with the text (FALSE
, the default). IfTRUE
, any parameters or aesthetics relating to the drawing of the path will be ignored.gap
A
logical(1)
which ifTRUE
, breaks the path into two sections with a gap on either side of the label. IfFALSE
, the path is plotted as a whole. Alternatively, ifNA
, the path will be broken if the string has avjust
between 0 and 1, and not otherwise. The default for the label variant isFALSE
and for the text variant isNA
.upright
A
logical(1)
which ifTRUE
(default), inverts any text where the majority of letters would upside down along the path, to improve legibility. IfFALSE
, the path decides the orientation of text.halign
A
character(1)
describing how multi-line text should be justified. Can either be"center"
(default),"left"
or"right"
.offset
A
unit
object of length 1 to determine the offset of the text from the path. If this isNULL
(default), thevjust
parameter decides the offset. If notNULL
, theoffset
argument overrules thevjust
setting.parse
A
logical(1)
which ifTRUE
, will coerce the labels into expressions, allowing for plotmath syntax to be used.straight
A
logical(1)
which ifTRUE
, keeps the letters of a label on a straight baseline and ifFALSE
(default), lets individual letters follow the curve. This might be helpful for noisy paths.padding
A
unit
object of length 1 to determine the padding between the text and the path when thegap
parameter trims the path.text_smoothing
a
numeric(1)
value between 0 and 100 that smooths the text without affecting the line portion of the geom. The default value of0
means no smoothing is applied.rich
A
logical(1)
whether to interpret the text as html/markdown formatted rich text. Default:FALSE
. See also the rich text section of the details ingeom_textpath()
.remove_long
if TRUE, labels that are longer than their associated path will be removed.
label.padding
Amount of padding around label. Defaults to 0.25 lines.
label.r
Radius of rounded corners. Defaults to 0.15 lines.
Details
Aesthetics
geom_cnt_text()
understands the following aesthetics:
x
y
label
alpha
angle
colour
family
fontface
group
hjust
linecolour
lineheight
linetype
linewidth
size
spacing
textcolour
vjust
In addition to aforementioned aesthetics, geom_cnt_label()
also
understands:
boxcolour
boxlinetype
boxlinewidth
fill
Examples
library(sf)
library(ggplot2)
lake <-
sf::st_read(
system.file("extdata/example.gpkg", package = "centerline"),
layer = "lake",
quiet = TRUE
)
# Plot centerline and lake name as text
ggplot() +
geom_sf(data = lake) +
geom_cnt_text(
data = lake,
aes(label = "Lake Ohau"),
size = 8,
simplify = TRUE
) +
theme_void()
# Plot lake name as label
ggplot() +
geom_sf(data = lake) +
geom_cnt_label(
data = lake,
aes(label = "Lake Ohau"),
linecolor = NA, # disable line drawing
size = 10,
method = "s",
simplify = TRUE
) +
theme_void()