Skip to content

Commit 84cded8

Browse files
authored
Crosslink aesthetics documentation (#5124)
* Connect scales to aes documentation * Improvements to aes documentation * Crosslink aes documentation * Match aes to doc page * Prevent having to import `relist()` * Better crosslinks for position scales * Roxygenate * Add NEWS bullet * Fix clumsy merge * Fix clumsy merge part II
1 parent 152d1d5 commit 84cded8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+623
-274
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ggplot2 (development version)
22

3+
* Aesthetics listed in `geom_*()` and `stat_*()` layers now point to relevant
4+
documentation (@teunbrand, #5123).
35
* `coord_flip()` has been marked as superseded. The recommended alternative is
46
to swap the `x` and `y` aesthetic and/or using the `orientation` argument in
57
a layer (@teunbrand, #5130).

R/aes-colour-fill-alpha.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#'
99
#' @section Colour and fill:
1010
#'
11+
#' The `colour` aesthetic is used to draw lines and strokes, such as in
12+
#' [`geom_point()`] and [`geom_line()`], but also the line contours of
13+
#' [`geom_rect()`] and [`geom_polygon()`]. The `fill` aesthetic is used to
14+
#' colour the inside areas of geoms, such as [`geom_rect()`] and
15+
#' [`geom_polygon()`], but also the insides of shapes 21-25 of [`geom_point()`].
16+
#'
1117
#' Colours and fills can be specified in the following ways:
1218
#' * A name, e.g., `"red"`. R has 657 built-in named colours, which can be
1319
#' listed with [grDevices::colors()].
@@ -38,9 +44,11 @@
3844
#' [scale_fill_gradient()], [scale_fill_grey()],
3945
#' [scale_fill_hue()], [scale_fill_identity()],
4046
#' [scale_fill_manual()], [scale_fill_viridis_d()]
41-
#' * Other options for modifying alpha: [scale_alpha()]
42-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
47+
#' * Other options for modifying alpha:
48+
#' [scale_alpha()], [scale_alpha_manual()], [scale_alpha_identity()]
49+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
4350
#' can be modified.
51+
#' @family aesthetics documentation
4452
#'
4553
#' @name aes_colour_fill_alpha
4654
#' @aliases colour color fill

R/aes-group-order.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@
1616
#' and/or `linetype`. This is demonstrated in the examples below.
1717
#'
1818
#' There are three common cases where the default does not display the data correctly.
19+
#' 1. `geom_line()` where there are multiple individuals and the plot tries to
20+
#' connect every observation, even across individuals, with a line.
21+
#' 1. `geom_line()` where a discrete x-position implies groups, whereas observations
22+
#' span the discrete x-positions.
23+
#' 1. When the grouping needs to be different over different layers, for example
24+
#' when computing a statistic on all observations when another layer shows
25+
#' individuals.
26+
#'
1927
#' The examples below use a longitudinal dataset, `Oxboys`, from the nlme package to demonstrate
2028
#' these cases. `Oxboys` records the heights (height) and centered ages (age) of 26 boys (Subject),
2129
#' measured on nine occasions (Occasion).
2230
#'
2331
#' @seealso
2432
#' * Geoms commonly used with groups: [geom_bar()], [geom_histogram()], [geom_line()]
25-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
33+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
2634
#' can be modified.
35+
#' @family aesthetics documentation
2736
#'
2837
#' @examples
2938
#' \donttest{

R/aes-linetype-size-shape.R

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
#' Differentiation related aesthetics: linetype, size, shape
22
#'
33
#' @description
4-
#' The `linetype`, `size`, and `shape` aesthetics modify the appearance of
5-
#' lines and/or points. They also apply to the outlines of polygons (`linetype`
6-
#' and `size`) or to text (`size`).
4+
#' The `linetype`, `linewidth`, `size`, and `shape` aesthetics modify the
5+
#' appearance of lines and/or points. They also apply to the outlines of
6+
#' polygons (`linetype` and `linewidth`) or to text (`size`).
77
#'
8+
#' @section Linetype:
89
#' The `linetype` aesthetic can be specified with either an integer (0-6), a
910
#' name (0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash,
1011
#' 6 = twodash), a mapping to a discrete variable, or a string of an even number
1112
#' (up to eight) of hexadecimal digits which give the lengths in consecutive
1213
#' positions in the string. See examples for a hex string demonstration.
1314
#'
14-
#' The `size` aesthetic can be specified with a numerical value (in millimetres)
15-
#' or via a mapping to a continuous variable.
15+
#' @section Linewidth and stroke:
16+
#' The `linewidth` aesthetic sets the widths of lines, and can be specified
17+
#' with a numeric value (for historical reasons, these units are about 0.75
18+
#' millimetres). Alternatively, they can also be set via mapping to a continuous
19+
#' variable. The `stroke` aesthetic serves the same role for points, but is
20+
#' distinct for discriminating points from lines in geoms such as
21+
#' [`geom_pointrange()`].
1622
#'
17-
#' The `shape` aesthetic can be specified with an integer (between 0 and 25),
18-
#' a single character (which uses that character as the plotting symbol),
19-
#' a `.` to draw the smallest rectangle that is visible (i.e., about one pixel),
20-
#' an `NA` to draw nothing, or a mapping to a discrete variable. Symbols and
21-
#' filled shapes are described in the examples below.
23+
#' @section Size:
24+
#' The `size` aesthetic control the size of points and text, and can be
25+
#' specified with a numerical value (in millimetres) or via a mapping to a
26+
#' continuous variable.
27+
#'
28+
#' @section Shape:
29+
#' The `shape` aesthetic controls the symbols of points, and can be specified
30+
#' with an integer (between 0 and 25), a single character (which uses that
31+
#' character as the plotting symbol), a `.` to draw the smallest rectangle that
32+
#' is visible (i.e., about one pixel), an `NA` to draw nothing, or a mapping to
33+
#' a discrete variable. Symbols and filled shapes are described in the examples
34+
#' below.
2235
#'
2336
#' @seealso
2437
#' * [geom_line()] and [geom_point()] for geoms commonly used
2538
#' with these aesthetics.
2639
#' * [aes_group_order()] for using `linetype`, `size`, or
2740
#' `shape` for grouping.
28-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
41+
#' * Scales that can be used to modify these aesthetics: [`scale_linetype()`],
42+
#' [`scale_linewidth()`], [`scale_size()`], and [`scale_shape()`].
43+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
2944
#' can be modified.
45+
#' @family aesthetics documentation
3046
#' @name aes_linetype_size_shape
3147
#' @aliases linetype size shape
3248
#' @examples
@@ -45,6 +61,12 @@
4561
#' ggplot(economics_long, aes(date, value01)) +
4662
#' geom_line(aes(linetype = variable))
4763
#'
64+
#' # Linewidth examples
65+
#' ggplot(economics, aes(date, unemploy)) +
66+
#' geom_line(linewidth = 2, lineend = "round")
67+
#' ggplot(economics, aes(date, unemploy)) +
68+
#' geom_line(aes(linewidth = uempmed), lineend = "round")
69+
#'
4870
#' # Size examples
4971
#' p <- ggplot(mtcars, aes(wt, mpg))
5072
#' p + geom_point(size = 4)

R/aes-position.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#' `xmin`, `xmax`, `ymin` and `ymax` can be used to specify the position of
1313
#' annotations and to represent rectangular areas.
1414
#'
15+
#' In addition, there are position aesthetics that are contextual to the
16+
#' geometry that they're used in. These are `xintercept`, `yintercept`,
17+
#' `xmin_final`, `ymin_final`, `xmax_final`, `ymax_final`, `xlower`, `lower`,
18+
#' `xmiddle`, `middle`, `xupper`, `upper`, `x0` and `y0`. Many of these are used
19+
#' and automatically computed in [`geom_boxplot()`].
20+
#'
1521
#' @name aes_position
1622
#' @aliases x y xmin xmax ymin ymax xend yend
1723
#'
@@ -20,7 +26,13 @@
2026
#' [geom_curve()], [geom_errorbar()], [geom_line()], [geom_linerange()],
2127
#' [geom_path()], [geom_point()], [geom_pointrange()], [geom_rect()],
2228
#' [geom_segment()]
29+
#' * Scales that can be used to modify positions:
30+
#' [`scale_continuous()`][scale_x_continuous()],
31+
#' [`scale_discrete()`][scale_x_discrete()],
32+
#' [`scale_binned()`][scale_x_binned()],
33+
#' [`scale_date()`][scale_x_date()].
2334
#' * See also [annotate()] for placing annotations.
35+
#' @family aesthetics documentation
2436
#' @examples
2537
#'
2638
#' # Generate data: means and standard errors of means for prices

R/aes.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ NULL
3333
#' @seealso [vars()] for another quoting function designed for
3434
#' faceting specifications.
3535
#'
36+
#' Run `vignette("ggplot2-specs")` to see an overview of other aesthetics
37+
#' that can be modified.
38+
#'
3639
#' [Delayed evaluation][aes_eval] for working with computed variables.
40+
#'
41+
#' @family aesthetics documentation
3742
#' @return A list with class `uneval`. Components of the list are either
3843
#' quosures or constants.
3944
#' @export

R/scale-alpha.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#' breaks, labels and so forth.
1111
#' @param range Output range of alpha values. Must lie between 0 and 1.
1212
#' @family colour scales
13+
#' @family alpha scales
14+
#' @seealso
15+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
16+
#'
17+
#' Other alpha scales: [scale_alpha_manual()], [scale_alpha_identity()].
1318
#' @export
1419
#' @examples
1520
#' p <- ggplot(mpg, aes(displ, hwy)) +

R/scale-binned.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#' @inheritParams binned_scale
99
#'
1010
#' @family position scales
11+
#' @seealso
12+
#' The [position documentation][aes_position].
1113
#' @name scale_binned
1214
#' @aliases NULL
1315
#'

R/scale-brewer.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#' or [binned_scale()], for `brewer`, `distiller`, and `fermenter` variants
3838
#' respectively, to control name, limits, breaks, labels and so forth.
3939
#' @family colour scales
40+
#' @seealso
41+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
4042
#' @rdname scale_brewer
4143
#' @export
4244
#' @examples

R/scale-colour.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#' @seealso [scale_colour_gradient()], [scale_colour_viridis_c()],
3636
#' [scale_colour_steps()], [scale_colour_viridis_b()], [scale_fill_gradient()],
3737
#' [scale_fill_viridis_c()], [scale_fill_steps()], and [scale_fill_viridis_b()]
38+
#'
39+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
3840
#' @family colour scales
3941
#' @rdname scale_colour_continuous
4042
#' @section Color Blindness:

0 commit comments

Comments
 (0)