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:

R/scale-continuous.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#'
1111
#' @inheritParams continuous_scale
1212
#' @family position scales
13+
#' @seealso
14+
#' The [position documentation][aes_position].
15+
#'
1316
#' @param ... Other arguments passed on to `scale_(x|y)_continuous()`
1417
#' @examples
1518
#' p1 <- ggplot(mpg, aes(displ, hwy)) +

R/scale-date.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
#' @param timezone The timezone to use for display on the axes. The default
3535
#' (`NULL`) uses the timezone encoded in the data.
3636
#' @family position scales
37-
#' @seealso [sec_axis()] for how to specify secondary axes
37+
#' @seealso
38+
#' [sec_axis()] for how to specify secondary axes
39+
#'
40+
#' The [position documentation][aes_position].
3841
#' @examples
3942
#' last_month <- Sys.Date() - 0:29
4043
#' set.seed(1)

R/scale-discrete-.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#' @inheritParams discrete_scale
1515
#' @rdname scale_discrete
1616
#' @family position scales
17+
#' @seealso
18+
#' The [position documentation][aes_position].
1719
#' @export
1820
#' @examples
1921
#' ggplot(diamonds, aes(cut)) + geom_bar()

R/scale-gradient.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#' @inheritDotParams continuous_scale -na.value -guide -aesthetics
2020
#' @seealso [scales::seq_gradient_pal()] for details on underlying
2121
#' palette, [scale_colour_steps()] for binned variants of these scales.
22+
#'
23+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
2224
#' @family colour scales
2325
#' @rdname scale_gradient
2426
#' @export

R/scale-grey.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#' @inheritParams scale_colour_hue
88
#' @inheritDotParams discrete_scale
99
#' @family colour scales
10+
#' @seealso
11+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
1012
#' @rdname scale_grey
1113
#' @export
1214
#' @examples

R/scale-hue.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#' @rdname scale_hue
1414
#' @export
1515
#' @family colour scales
16+
#' @seealso
17+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
1618
#' @examples
1719
#' \donttest{
1820
#' set.seed(596)

R/scale-identity.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#' example, to apply colour settings to the `colour` and `fill` aesthetics at the
2222
#' same time, via `aesthetics = c("colour", "fill")`.
2323
#' @param guide Guide to use for this scale. Defaults to `"none"`.
24+
#' @family colour scales
2425
#' @examples
2526
#' ggplot(luv_colours, aes(u, v)) +
2627
#' geom_point(aes(colour = col), size = 3) +
@@ -78,6 +79,8 @@ scale_fill_identity <- function(..., guide = "none", aesthetics = "fill") {
7879
}
7980

8081
#' @rdname scale_identity
82+
#' @seealso
83+
#' Other shape scales: [scale_shape()], [scale_shape_manual()].
8184
#' @export
8285
scale_shape_identity <- function(..., guide = "none") {
8386
sc <- continuous_scale("shape", "identity", identity_pal(), ..., guide = guide,
@@ -87,6 +90,8 @@ scale_shape_identity <- function(..., guide = "none") {
8790
}
8891

8992
#' @rdname scale_identity
93+
#' @seealso
94+
#' Other linetype scales: [scale_linetype()], [scale_linetype_manual()].
9095
#' @export
9196
scale_linetype_identity <- function(..., guide = "none") {
9297
sc <- discrete_scale("linetype", "identity", identity_pal(), ..., guide = guide,
@@ -96,6 +101,8 @@ scale_linetype_identity <- function(..., guide = "none") {
96101
}
97102

98103
#' @rdname scale_identity
104+
#' @seealso
105+
#' Other alpha scales: [scale_alpha()], [scale_alpha_manual()].
99106
#' @export
100107
scale_linewidth_identity <- function(..., guide = "none") {
101108
sc <- continuous_scale("linewidth", "identity", identity_pal(), ...,
@@ -114,6 +121,8 @@ scale_alpha_identity <- function(..., guide = "none") {
114121
}
115122

116123
#' @rdname scale_identity
124+
#' @seealso
125+
#' Other size scales: [scale_size()], [scale_size_manual()].
117126
#' @export
118127
scale_size_identity <- function(..., guide = "none") {
119128
sc <- continuous_scale("size", "identity", identity_pal(), ..., guide = guide,

R/scale-linetype.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#' @inheritDotParams discrete_scale -expand -position -na.value
1010
#' @param na.value The linetype to use for `NA` values.
1111
#' @rdname scale_linetype
12+
#' @seealso
13+
#' The documentation for [differentiation related aesthetics][aes_linetype_size_shape].
14+
#'
15+
#' Other linetype scales: [scale_linetype_manual()], [scale_linetype_identity()].
1216
#' @export
1317
#' @examples
1418
#' base <- ggplot(economics_long, aes(date, value01))

R/scale-linewidth.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#' @name scale_linewidth
99
#' @inheritParams continuous_scale
1010
#' @inheritParams binned_scale
11+
#' @seealso
12+
#' The documentation for [differentiation related aesthetics][aes_linetype_size_shape].
1113
#' @param range a numeric vector of length 2 that specifies the minimum and
1214
#' maximum size of the plotting symbol after transformation.
1315
#' @examples

R/scale-manual.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#' - A function that takes the limits as input and returns breaks
3030
#' as output
3131
#' @param na.value The aesthetic value to use for missing (`NA`) values
32+
#' @family colour scales
33+
#' @seealso
34+
#' The documentation for [differentiation related aesthetics][aes_linetype_size_shape].
35+
#'
36+
#' The documentation on [colour aesthetics][aes_colour_fill_alpha].
3237
#'
3338
#' @section Color Blindness:
3439
#' Many color palettes derived from RGB combinations (like the "rainbow" color
@@ -93,24 +98,32 @@ scale_fill_manual <- function(..., values, aesthetics = "fill", breaks = waiver(
9398
}
9499

95100
#' @rdname scale_manual
101+
#' @seealso
102+
#' Other size scales: [scale_size()], [scale_size_identity()].
96103
#' @export
97104
scale_size_manual <- function(..., values, breaks = waiver(), na.value = NA) {
98105
manual_scale("size", values, breaks, ..., na.value = na.value)
99106
}
100107

101108
#' @rdname scale_manual
109+
#' @seealso
110+
#' Other shape scales: [scale_shape()], [scale_shape_identity()].
102111
#' @export
103112
scale_shape_manual <- function(..., values, breaks = waiver(), na.value = NA) {
104113
manual_scale("shape", values, breaks, ..., na.value = na.value)
105114
}
106115

107116
#' @rdname scale_manual
117+
#' @seealso
118+
#' Other linetype scales: [scale_linetype()], [scale_linetype_identity()].
108119
#' @export
109120
scale_linetype_manual <- function(..., values, breaks = waiver(), na.value = "blank") {
110121
manual_scale("linetype", values, breaks, ..., na.value = na.value)
111122
}
112123

113124
#' @rdname scale_manual
125+
#' @seealso
126+
#' Other alpha scales: [scale_alpha()], [scale_alpha_identity()].
114127
#' @export
115128
scale_linewidth_manual <- function(..., values, breaks = waiver(), na.value = NA) {
116129
manual_scale("linewidth", values, breaks, ..., na.value = na.value)

R/scale-shape.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#' @inheritParams scale_x_discrete
1313
#' @inheritDotParams discrete_scale -expand -position
1414
#' @rdname scale_shape
15+
#' @seealso
16+
#' The documentation for [differentiation related aesthetics][aes_linetype_size_shape].
17+
#'
18+
#' Other shape scales: [scale_shape_manual()], [scale_shape_identity()].
1519
#' @export
1620
#' @examples
1721
#' set.seed(596)

R/scale-size.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#' @seealso [scale_size_area()] if you want 0 values to be mapped
2323
#' to points with size 0. [scale_linewidth()] if you want to scale the width
2424
#' of lines.
25+
#'
26+
#' The documentation for [differentiation related aesthetics][aes_linetype_size_shape].
2527
#' @examples
2628
#' p <- ggplot(mpg, aes(displ, hwy, size = hwy)) +
2729
#' geom_point()

0 commit comments

Comments
 (0)