Skip to content

Commit 442108d

Browse files
author
Dana Paige Seidel
authored
Update theme documentation (#2791)
closes #2553
1 parent 344bfea commit 442108d

File tree

2 files changed

+170
-291
lines changed

2 files changed

+170
-291
lines changed

R/theme.r

Lines changed: 84 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,77 @@
11
#' Modify components of a theme
22
#'
3-
#' Use `theme()` to modify individual components of a theme, allowing
4-
#' you to control the appearance of all non-data components of the plot.
5-
#' `theme()` only affects a single plot: see [theme_update()] if
6-
#' you want modify the active theme, to affect all subsequent plots.
3+
#' Themes are a powerful way to customize the non-data components of your
4+
#' plots: i.e. titles, labels, fonts, background, gridlines, and legends.
5+
#' Themes can be used to give plots a consistent customized look.
6+
#' Modify a single plot's theme using `theme()`; see [theme_update()] if
7+
#' you want modify the active theme, to affect all subsequent plots. Theme
8+
#' elements are documented together according to inheritance, read more
9+
#' about theme inheritance below.
710
#'
811
#' @section Theme inheritance:
9-
#' Theme elements inherit properties from other theme elements.
10-
#' For example, `axis.title.x` inherits from `axis.title`,
11-
#' which in turn inherits from `text`. All text elements inherit
12+
#' Theme elements inherit properties from other theme elements heirarchically.
13+
#' For example, `axis.title.x.bottom` inherits from `axis.title.x` which inherits
14+
#' from `axis.title`, which in turn inherits from `text`. All text elements inherit
1215
#' directly or indirectly from `text`; all lines inherit from
1316
#' `line`, and all rectangular objects inherit from `rect`.
1417
#' This means that you can modify the appearance of multiple elements by
1518
#' setting a single high-level component.
1619
#'
17-
#' @param line all line elements (`element_line`)
18-
#' @param rect all rectangular elements (`element_rect`)
19-
#' @param text all text elements (`element_text`)
20-
#' @param title all title elements: plot, axes, legends (`element_text`;
20+
#' Learn more about setting these aesthetics in `vignette("ggplot2-specs")`.
21+
#'
22+
#' @param line all line elements ([element_line()])
23+
#' @param rect all rectangular elements ([element_rect()])
24+
#' @param text all text elements ([element_text()])
25+
#' @param title all title elements: plot, axes, legends ([element_text()];
2126
#' inherits from `text`)
2227
#' @param aspect.ratio aspect ratio of the panel
2328
#'
24-
#' @param axis.title label of axes (`element_text`; inherits from
25-
#' `text`)
26-
#' @param axis.title.x x axis label (`element_text`; inherits from
27-
#' `axis.title`)
28-
#' @param axis.title.x.top x axis label on top axis (`element_text`;
29-
#' inherits from `axis.title.x`)
30-
#' @param axis.title.x.bottom x axis label on bottom axis (`element_text`;
31-
#' inherits from `axis.title.x`)
32-
#' @param axis.title.y y axis label (`element_text`; inherits from
33-
#' `axis.title`)
34-
#' @param axis.title.y.left y axis label on left axis (`element_text`;
35-
#' inherits from `axis.title.y`)
36-
#' @param axis.title.y.right y axis label on right axis (`element_text`;
37-
#' inherits from `axis.title.y`)
38-
#' @param axis.text tick labels along axes (`element_text`; inherits from
39-
#' `text`)
40-
#' @param axis.text.x x axis tick labels (`element_text`; inherits from
41-
#' `axis.text`)
42-
#' @param axis.text.x.top x axis tick labels on top axis (`element_text`;
43-
#' inherits from `axis.text.x`)
44-
#' @param axis.text.x.bottom x axis tick labels on bottom axis (`element_text`;
45-
#' inherits from `axis.text.x`)
46-
#' @param axis.text.y y axis tick labels (`element_text`; inherits from
47-
#' `axis.text`)
48-
#' @param axis.text.y.left y axis tick labels on left axis
49-
#' (`element_text`; inherits from `axis.text.y`)
50-
#' @param axis.text.y.right y axis tick labels on right axis
51-
#' (`element_text`; inherits from `axis.text.y`)
52-
#' @param axis.ticks tick marks along axes (`element_line`; inherits from
53-
#' `line`)
54-
#' @param axis.ticks.x x axis tick marks (`element_line`; inherits from
55-
#' `axis.ticks`)
56-
#' @param axis.ticks.x.top x axis tick marks on top axis (`element_line`;
57-
#' inherits from `axis.ticks.x`)
58-
#' @param axis.ticks.x.bottom x axis tick marks on bottom axis (`element_line`;
59-
#' inherits from `axis.ticks.x`)
60-
#' @param axis.ticks.y y axis tick marks (`element_line`; inherits from
61-
#' `axis.ticks`)
62-
#' @param axis.ticks.y.left y axis tick marks on left axis (`element_line`;
63-
#' inherits from `axis.ticks.y`)
64-
#' @param axis.ticks.y.right y axis tick marks on right axis (`element_line`;
65-
#' inherits from `axis.ticks.y`)
29+
#' @param axis.title,axis.title.x,axis.title.y,axis.title.x.top,axis.title.x.bottom,axis.title.y.left,axis.title.y.right
30+
#' labels of axes ([element_text()]). Specify all axes' labels (`axis.title`),
31+
#' labels by plane (using `axis.title.x` or `axis.title.y`), or individually
32+
#' for each axis (using `axis.title.x.bottom`, `axis.title.x.top`,
33+
#' `axis.title.y.left`, `axis.title.y.right`). `axis.title.*.*` inherits from
34+
#' `axis.title.*` which inherits from `axis.title`, which in turn inherits
35+
#' from `text`
36+
#' @param axis.text,axis.text.x,axis.text.y,axis.text.x.top,axis.text.x.bottom,axis.text.y.left,axis.text.y.right
37+
#' tick labels along axes ([element_text()]). Specify all axis tick labels (`axis.text`),
38+
#' tick labels by plane (using `axis.text.x` or `axis.text.y`), or individually
39+
#' for each axis (using `axis.text.x.bottom`, `axis.text.x.top`,
40+
#' `axis.text.y.left`, `axis.text.y.right`). `axis.text.*.*` inherits from
41+
#' `axis.text.*` which inherits from `axis.text`, which in turn inherits
42+
#' from `text`
43+
#' @param axis.ticks,axis.ticks.x,axis.ticks.x.top,axis.ticks.x.bottom,axis.ticks.y,axis.ticks.y.left,axis.ticks.y.right
44+
#' tick marks along axes ([element_line()]). Specify all tick marks (`axis.ticks`),
45+
#' ticks by plane (using `axis.ticks.x` or `axis.ticks.y`), or individually
46+
#' for each axis (using `axis.ticks.x.bottom`, `axis.ticks.x.top`,
47+
#' `axis.ticks.y.left`, `axis.ticks.y.right`). `axis.ticks.*.*` inherits from
48+
#' `axis.ticks.*` which inherits from `axis.ticks`, which in turn inherits
49+
#' from `line`
6650
#' @param axis.ticks.length length of tick marks (`unit`)
67-
#' @param axis.line lines along axes (`element_line`; inherits from
68-
#' `line`)
69-
#' @param axis.line.x line along x axis (`element_line`; inherits from
70-
#' `axis.line`)
71-
#' @param axis.line.x.top line along x axis on top axis (`element_line`;
72-
#' inherits from `axis.line.x`)
73-
#' @param axis.line.x.bottom line along x axis on bottom axis (`element_line`;
74-
#' inherits from `axis.line.x`)
75-
#' @param axis.line.y line along y axis (`element_line`; inherits from
76-
#' `axis.line`)
77-
#' @param axis.line.y.left line along y axis on left axis (`element_line`;
78-
#' inherits from `axis.line.y`)
79-
#' @param axis.line.y.right line along y axis on right axis (`element_line`;
80-
#' inherits from `axis.line.y`)
81-
#'
82-
#' @param legend.background background of legend (`element_rect`; inherits
51+
#' @param axis.line,axis.line.x,axis.line.x.top,axis.line.x.bottom,axis.line.y,axis.line.y.left,axis.line.y.right
52+
#' lines along axes ([element_line()]). Specify lines along all axes (`axis.line`),
53+
#' lines for each plane (using `axis.line.x` or `axis.line.y`), or individually
54+
#' for each axis (using `axis.line.x.bottom`, `axis.line.x.top`,
55+
#' `axis.line.y.left`, `axis.line.y.right`). `axis.line.*.*` inherits from
56+
#' `axis.line.*` which inherits from `axis.line`, which in turn inherits
57+
#' from `line`
58+
#'
59+
#' @param legend.background background of legend ([element_rect()]; inherits
8360
#' from `rect`)
84-
#' @param legend.margin the margin around each legend (`margin`)
85-
#' @param legend.spacing the spacing between legends (`unit`)
86-
#' @param legend.spacing.x the horizontal spacing between legends (`unit`);
87-
#' inherits from `legend.spacing`
88-
#' @param legend.spacing.y the vertical spacing between legends (`unit`);
89-
#' inherits from `legend.spacing`
90-
#' @param legend.key background underneath legend keys (`element_rect`;
61+
#' @param legend.margin the margin around each legend ([margin()])
62+
#' @param legend.spacing,legend.spacing.x,legend.spacing.y
63+
#' the spacing between legends (`unit`). `legend.spacing.x` & `legend.spacing.y`
64+
#' inherit from `legend.spacing` or can be specified separately
65+
#' @param legend.key background underneath legend keys ([element_rect()];
9166
#' inherits from `rect`)
92-
#' @param legend.key.size size of legend keys (`unit`)
93-
#' @param legend.key.height key background height (`unit`; inherits from
94-
#' `legend.key.size`)
95-
#' @param legend.key.width key background width (`unit`; inherits from
96-
#' `legend.key.size`)
97-
#' @param legend.text legend item labels (`element_text`; inherits from
67+
#' @param legend.key.size,legend.key.height,legend.key.width
68+
#' size of legend keys (`unit`); key background height & width inherit from
69+
#' `legend.key.size` or can be specified separately
70+
#' @param legend.text legend item labels ([element_text()]; inherits from
9871
#' `text`)
9972
#' @param legend.text.align alignment of legend labels (number from 0 (left) to
10073
#' 1 (right))
101-
#' @param legend.title title of legend (`element_text`; inherits from
74+
#' @param legend.title title of legend ([element_text()]; inherits from
10275
#' `title`)
10376
#' @param legend.title.align alignment of legend title (number from 0 (left) to
10477
#' 1 (right))
@@ -116,71 +89,61 @@
11689
#' "right")
11790
#' @param legend.box.margin margins around the full legend area, as specified
11891
#' using [margin()]
119-
#' @param legend.box.background background of legend area (`element_rect`;
92+
#' @param legend.box.background background of legend area ([element_rect()];
12093
#' inherits from `rect`)
12194
#' @param legend.box.spacing The spacing between the plotting area and the
12295
#' legend box (`unit`)
12396
#'
12497
#' @param panel.background background of plotting area, drawn underneath plot
125-
#' (`element_rect`; inherits from `rect`)
98+
#' ([element_rect()]; inherits from `rect`)
12699
#' @param panel.border border around plotting area, drawn on top of plot so that
127100
#' it covers tick marks and grid lines. This should be used with
128101
#' `fill = NA`
129-
#' (`element_rect`; inherits from `rect`)
130-
#' @param panel.spacing spacing between facet panels (`unit`)
131-
#' @param panel.spacing.x horizontal spacing between facet panels (`unit`;
132-
#' inherits from `panel.spacing`)
133-
#' @param panel.spacing.y vertical spacing between facet panels (`unit`;
134-
#' inherits from `panel.spacing`)
135-
#' @param panel.grid grid lines (`element_line`; inherits from `line`)
136-
#' @param panel.grid.major major grid lines (`element_line`; inherits from
137-
#' `panel.grid`)
138-
#' @param panel.grid.minor minor grid lines (`element_line`; inherits from
139-
#' `panel.grid`)
140-
#' @param panel.grid.major.x vertical major grid lines (`element_line`;
141-
#' inherits from `panel.grid.major`)
142-
#' @param panel.grid.major.y horizontal major grid lines (`element_line`;
143-
#' inherits from `panel.grid.major`)
144-
#' @param panel.grid.minor.x vertical minor grid lines (`element_line`;
145-
#' inherits from `panel.grid.minor`)
146-
#' @param panel.grid.minor.y horizontal minor grid lines (`element_line`;
147-
#' inherits from `panel.grid.minor`)
102+
#' ([element_rect()]; inherits from `rect`)
103+
#' @param panel.spacing,panel.spacing.x,panel.spacing.y spacing between facet
104+
#' panels (`unit`). `panel.spacing.x` & `panel.spacing.y` inherit from `panel.spacing`
105+
#' or can be specified separately.
106+
#' @param panel.grid,panel.grid.major,panel.grid.minor,panel.grid.major.x,panel.grid.major.y,panel.grid.minor.x,panel.grid.minor.y
107+
#' grid lines ([element_line()]). Specify major grid lines,
108+
#' or minor grid lines separately (using `panel.grid.major` or `panel.grid.minor`)
109+
#' or individually for each axis (using `panel.grid.major.x`, `panel.grid.minor.x`,
110+
#' `panel.grid.major.y`, `panel.grid.minor.y`). Y axis grid lines are horizontal
111+
#' and x axis grid lines are vertical. `panel.grid.*.*` inherits from
112+
#' `panel.grid.*` which inherits from `panel.grid`, which in turn inherits
113+
#' from `line`
148114
#' @param panel.ontop option to place the panel (background, gridlines) over
149115
#' the data layers (`logical`). Usually used with a transparent or blank
150116
#' `panel.background`.
151117
#'
152-
#' @param plot.background background of the entire plot (`element_rect`;
118+
#' @param plot.background background of the entire plot ([element_rect()];
153119
#' inherits from `rect`)
154-
#' @param plot.title plot title (text appearance) (`element_text`; inherits
120+
#' @param plot.title plot title (text appearance) ([element_text()]; inherits
155121
#' from `title`) left-aligned by default
156-
#' @param plot.subtitle plot subtitle (text appearance) (`element_text`;
122+
#' @param plot.subtitle plot subtitle (text appearance) ([element_text()];
157123
#' inherits from `title`) left-aligned by default
158124
#' @param plot.caption caption below the plot (text appearance)
159-
#' (`element_text`; inherits from `title`) right-aligned by default
125+
#' ([element_text()]; inherits from `title`) right-aligned by default
160126
#' @param plot.tag upper-left label to identify a plot (text appearance)
161-
#' (`element_text`; inherits from `title`) left-aligned by default
127+
#' ([element_text()]; inherits from `title`) left-aligned by default
162128
#' @param plot.tag.position The position of the tag as a string ("topleft",
163129
#' "top", "topright", "left", "right", "bottomleft", "bottom", "bottomright)
164130
#' or a coordinate. If a string, extra space will be added to accommodate the
165131
#' tag.
166132
#' @param plot.margin margin around entire plot (`unit` with the sizes of
167133
#' the top, right, bottom, and left margins)
168134
#'
169-
#' @param strip.background background of facet labels (`element_rect`;
170-
#' inherits from `rect`)
171-
#' @param strip.background.x background of horizontal facet labels
172-
#' (`element_rect`; inherits from `strip.background`)
173-
#' @param strip.background.y background of vertical facet labels
174-
#' (`element_rect`; inherits from `strip.background`)
135+
#' @param strip.background,strip.background.x,strip.background.y
136+
#' background of facet labels ([element_rect()];
137+
#' inherits from `rect`). Horizontal facet background (`strip.background.x`)
138+
#' & vertical facet background (`strip.background.y`) inherit from
139+
#' `strip.background` or can be specified separately
175140
#' @param strip.placement placement of strip with respect to axes,
176141
#' either "inside" or "outside". Only important when axes and strips are
177142
#' on the same side of the plot.
178-
#' @param strip.text facet labels (`element_text`; inherits from
179-
#' `text`)
180-
#' @param strip.text.x facet labels along horizontal direction
181-
#' (`element_text`; inherits from `strip.text`)
182-
#' @param strip.text.y facet labels along vertical direction
183-
#' (`element_text`; inherits from `strip.text`)
143+
#' @param strip.text,strip.text.x,strip.text.y facet labels ([element_text()];
144+
#' inherits from `text`). Horizontal facet labels (`strip.text.x`) & vertical
145+
#' facet labels (`strip.text.y`) inherit from `strip.text` or can be specified
146+
#' separately
184147
#' @param strip.switch.pad.grid space between strips and axes when strips are
185148
#' switched (`unit`)
186149
#' @param strip.switch.pad.wrap space between strips and axes when strips are

0 commit comments

Comments
 (0)