|
1 | 1 | #' Text |
2 | 2 | #' |
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. |
12 | 15 | #' |
13 | 16 | #' `geom_text()` and `geom_label()` add labels for each row in the |
14 | 17 | #' data, even if coordinates x, y are set to single values in the call |
15 | 18 | #' to `geom_label()` or `geom_text()`. |
16 | 19 | #' To add labels at specified points use [annotate()] with |
17 | 20 | #' `annotate(geom = "text", ...)` or `annotate(geom = "label", ...)`. |
18 | 21 | #' |
| 22 | +#' To automatically position non-overlapping text labels see the |
| 23 | +#' \href{https://cran.r-project.org/package=ggrepel}{ggrepel} |
| 24 | +#' package. |
| 25 | +#' |
19 | 26 | #' @eval rd_aesthetics("geom", "text") |
20 | 27 | #' @section `geom_label()`: |
21 | 28 | #' Currently `geom_label()` does not support the `angle` aesthetic and |
|
36 | 43 | #' displayed as described in `?plotmath`. |
37 | 44 | #' @param nudge_x,nudge_y Horizontal and vertical adjustment to nudge labels by. |
38 | 45 | #' 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`. |
39 | 50 | #' @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()`. |
41 | 54 | #' @export |
42 | 55 | #' @examples |
43 | 56 | #' p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) |
|
0 commit comments