Skip to content

Commit 5bc667e

Browse files
authored
Improve geom_text documentation (#3753) (#3771)
* Improve geom_text documentation. closes #3753
1 parent 14325b4 commit 5bc667e

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

R/geom-text.r

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#' Text
22
#'
3-
#' `geom_text()` adds text directly to the plot. `geom_label()` draws
4-
#' a rectangle behind the text, making it easier to read.
5-
#'
6-
#' Note that the "width" and "height" of a text element are 0, so stacking
7-
#' and dodging text will not work by default, and axis limits are not
8-
#' automatically expanded to include all text. Obviously, labels do have
9-
#' height and width, but they are physical units, not data units. The amount of
10-
#' space they occupy on the plot is not constant in data units: when you
11-
#' resize a plot, labels stay the same size, but the size of the axes changes.
3+
#' Text geoms are useful for labeling plots. They can be used by themselves as
4+
#' scatterplots or in cobination with other geoms, for example, for labeling
5+
#' points or for annotating the height of bars. `geom_text()` adds only text
6+
#' to the plot. `geom_label()` draws a rectangle behind the text, making it
7+
#' easier to read.
8+
#'
9+
#' Note that when you resize a plot, text labels stay the same size, even
10+
#' though the size of the plot area changes. This happens because the "width"
11+
#' and "height" of a text element are 0. Obviously, text labels do have height
12+
#' and width, but they are physical units, not data units. For the same reason,
13+
#' stacking and dodging text will not work by default, and axis limits are not
14+
#' automatically expanded to include all text.
1215
#'
1316
#' `geom_text()` and `geom_label()` add labels for each row in the
1417
#' data, even if coordinates x, y are set to single values in the call
1518
#' to `geom_label()` or `geom_text()`.
1619
#' To add labels at specified points use [annotate()] with
1720
#' `annotate(geom = "text", ...)` or `annotate(geom = "label", ...)`.
1821
#'
22+
#' To automatically position non-overlapping text labels see the
23+
#' \href{https://cran.r-project.org/package=ggrepel}{ggrepel}
24+
#' package.
25+
#'
1926
#' @eval rd_aesthetics("geom", "text")
2027
#' @section `geom_label()`:
2128
#' Currently `geom_label()` does not support the `angle` aesthetic and
@@ -36,8 +43,14 @@
3643
#' displayed as described in `?plotmath`.
3744
#' @param nudge_x,nudge_y Horizontal and vertical adjustment to nudge labels by.
3845
#' Useful for offsetting text from points, particularly on discrete scales.
46+
#' Cannot be jointy specified with `position`.
47+
#' @param position Position adjustment, either as a string, or the result of
48+
#' a call to a position adjustment function. Cannot be jointy specified with
49+
#' `nudge_x` or `nudge_y`.
3950
#' @param check_overlap If `TRUE`, text that overlaps previous text in the
40-
#' same layer will not be plotted.
51+
#' same layer will not be plotted. `check_overlap` happens at draw time and in
52+
#' the order of the data. Therefore data should be arranged by the label
53+
#' column before calling `geom_label()` or `geom_text()`.
4154
#' @export
4255
#' @examples
4356
#' p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))

man/geom_text.Rd

Lines changed: 22 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ggsf.Rd

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)