Skip to content

Commit 5d16382

Browse files
committed
Merge pull request #933 from jiho/theme_doc
Document all themes together
2 parents c46beb6 + 58e6baf commit 5d16382

File tree

8 files changed

+139
-205
lines changed

8 files changed

+139
-205
lines changed

R/theme-defaults.r

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,56 @@
1-
#' A theme with grey background and white gridlines.
1+
#' ggplot2 themes
2+
#'
3+
#' Themes set the general aspect of the plot such as the colour of the
4+
#' background, gridlines, the size and colour of fonts.
25
#'
36
#' @param base_size base font size
47
#' @param base_family base font family
5-
#' @aliases theme_gray theme_grey
6-
#' @export theme_gray theme_grey
7-
#' @family themes
8+
#'
9+
#' @details \describe{
10+
#'
11+
#' \item{\code{theme_gray}}
12+
#' {The signature ggplot2 theme with a grey background and white gridlines,
13+
#' designed to put the data forward yet make comparisons easy.}
14+
#'
15+
#' \item{\code{theme_bw}}
16+
#' {The classic dark-on-light ggplot2 theme. May work better for presentations
17+
#' displayed with a projector.}
18+
#'
19+
#' \item{\code{theme_linedraw}}
20+
#' {A theme with only black lines of various widths on white backgrounds,
21+
#' reminiscent of a line drawings. Serves a purpose similar to \code{theme_bw}.
22+
#' Note that this theme has some very thin lines (<< 1 pt) which some journals
23+
#' may refuse.}
24+
#'
25+
#' \item{\code{theme_light}}
26+
#' {A theme similar to \code{theme_linedraw} but with light grey lines and axes,
27+
#' to direct more attention towards the data.}
28+
#'
29+
#' \item{\code{theme_minimal}}
30+
#' {A minimalistic theme with no background annotations.}
31+
#'
32+
#' \item{\code{theme_classic}}
33+
#' {A classic-looking theme, with x and y axis lines and no gridlines.}
34+
#'
35+
#' }
36+
#'
37+
#' @examples
38+
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
39+
#' colour=factor(gear))) + facet_wrap(~am)
40+
#'
41+
#' p
42+
#' p + theme_gray()
43+
#' p + theme_bw()
44+
#' p + theme_linedraw()
45+
#' p + theme_light()
46+
#' p + theme_minimal()
47+
#' p + theme_classic()
48+
#'
49+
#' @name ggtheme
50+
NULL
51+
52+
#' @export
53+
#' @rdname ggtheme
854
theme_grey <- function(base_size = 12, base_family = "") {
955
theme(
1056
# Elements in this first block aren't used directly, but are inherited
@@ -59,15 +105,12 @@ theme_grey <- function(base_size = 12, base_family = "") {
59105
complete = TRUE
60106
)
61107
}
108+
#' @export
109+
#' @rdname ggtheme
62110
theme_gray <- theme_grey
63111

64-
65-
#' A theme with white background and dark gridlines.
66-
#'
67-
#' @param base_size base font size
68-
#' @param base_family base font family
69112
#' @export
70-
#' @family themes
113+
#' @rdname ggtheme
71114
theme_bw <- function(base_size = 12, base_family = "") {
72115
# Starts with theme_grey and then modify some parts
73116
theme_grey(base_size = base_size, base_family = base_family) %+replace%
@@ -84,21 +127,8 @@ theme_bw <- function(base_size = 12, base_family = "") {
84127
)
85128
}
86129

87-
#' A theme with white background and black gridlines.
88-
#'
89-
#' @param base_size base font size
90-
#' @param base_family base font family
91130
#' @export
92-
#' @family themes
93-
#' @examples
94-
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
95-
#' p
96-
#' # 'classic' dark-on-light theme
97-
#' p + theme_bw()
98-
#' # this theme
99-
#' p + theme_linedraw()
100-
#' # variation with light box and axes legends
101-
#' p + theme_light()
131+
#' @rdname ggtheme
102132
theme_linedraw <- function(base_size = 12, base_family = "") {
103133
# Starts with theme_grey and then modify some parts
104134
theme_grey(base_size = base_size, base_family = base_family) %+replace%
@@ -116,44 +146,27 @@ theme_linedraw <- function(base_size = 12, base_family = "") {
116146
)
117147
}
118148

119-
#' A theme with white background and light grey lines
120-
#'
121-
#' @param base_size base font size
122-
#' @param base_family base font family
123149
#' @export
124-
#' @family themes
125-
#' @examples
126-
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg))
127-
#' p
128-
#' # 'classic' dark-on-light theme
129-
#' p + theme_bw()
130-
#' # this theme
131-
#' p + theme_light()
132-
#' # variation with dark box and axes legends
133-
#' p + theme_linedraw()
150+
#' @rdname ggtheme
134151
theme_light <- function(base_size = 12, base_family = "") {
135152
# Starts with theme_grey and then modify some parts
136153
theme_grey(base_size = base_size, base_family = base_family) %+replace%
137154
theme(
138-
axis.ticks = element_line(colour = "grey50", size = 0.25),
155+
axis.ticks = element_line(colour = "grey70", size = 0.25),
139156
legend.key = element_rect(fill = "white", colour = "grey50", size = 0.25),
140157
panel.background = element_rect(fill = "white", colour = NA),
141-
panel.border = element_rect(fill = NA, colour = "grey50", size = 0.5),
142-
panel.grid.major = element_line(colour = "grey80", size = 0.25),
143-
panel.grid.minor = element_line(colour = "grey92", size = 0.125),
144-
strip.background = element_rect(fill = "grey50", colour = NA),
158+
panel.border = element_rect(fill = NA, colour = "grey70", size = 0.5),
159+
panel.grid.major = element_line(colour = "grey85", size = 0.25),
160+
panel.grid.minor = element_line(colour = "grey93", size = 0.125),
161+
strip.background = element_rect(fill = "grey70", colour = NA),
145162
strip.text.x = element_text(colour = "white"),
146163
strip.text.y = element_text(colour = "white", angle = -90)
147164
)
148165

149166
}
150167

151-
#' A minimalistic theme with no background annotations.
152-
#'
153-
#' @param base_size base font size
154-
#' @param base_family base font family
155168
#' @export
156-
#' @family themes
169+
#' @rdname ggtheme
157170
theme_minimal <- function(base_size = 12, base_family = "") {
158171
# Starts with theme_bw and then modify some parts
159172
theme_bw(base_size = base_size, base_family = base_family) %+replace%
@@ -167,12 +180,8 @@ theme_minimal <- function(base_size = 12, base_family = "") {
167180
)
168181
}
169182

170-
#' A classic-looking theme, with x and y axis lines and no gridlines.
171-
#'
172-
#' @param base_size base font size
173-
#' @param base_family base font family
174183
#' @export
175-
#' @family themes
184+
#' @rdname ggtheme
176185
theme_classic <- function(base_size = 12, base_family = ""){
177186
theme_bw(base_size = base_size, base_family = base_family) %+replace%
178187
theme(

man/ggtheme.Rd

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
% Generated by roxygen2 (4.0.0): do not edit by hand
2+
\name{ggtheme}
3+
\alias{ggtheme}
4+
\alias{theme_bw}
5+
\alias{theme_classic}
6+
\alias{theme_gray}
7+
\alias{theme_grey}
8+
\alias{theme_light}
9+
\alias{theme_linedraw}
10+
\alias{theme_minimal}
11+
\title{ggplot2 themes}
12+
\usage{
13+
theme_grey(base_size = 12, base_family = "")
14+
15+
theme_gray(base_size = 12, base_family = "")
16+
17+
theme_bw(base_size = 12, base_family = "")
18+
19+
theme_linedraw(base_size = 12, base_family = "")
20+
21+
theme_light(base_size = 12, base_family = "")
22+
23+
theme_minimal(base_size = 12, base_family = "")
24+
25+
theme_classic(base_size = 12, base_family = "")
26+
}
27+
\arguments{
28+
\item{base_size}{base font size}
29+
30+
\item{base_family}{base font family}
31+
}
32+
\description{
33+
Themes set the general aspect of the plot such as the colour of the
34+
background, gridlines, the size and colour of fonts.
35+
}
36+
\details{
37+
\describe{
38+
39+
\item{\code{theme_gray}}
40+
{The signature ggplot2 theme with a grey background and white gridlines,
41+
designed to put the data forward yet make comparisons easy.}
42+
43+
\item{\code{theme_bw}}
44+
{The classic dark-on-light ggplot2 theme. May work better for presentations
45+
displayed with a projector.}
46+
47+
\item{\code{theme_linedraw}}
48+
{A theme with only black lines of various widths on white backgrounds,
49+
reminiscent of a line drawings. Serves a purpose similar to \code{theme_bw}.
50+
Note that this theme has some very thin lines (<< 1 pt) which some journals
51+
may refuse.}
52+
53+
\item{\code{theme_light}}
54+
{A theme similar to \code{theme_linedraw} but with light grey lines and axes,
55+
to direct more attention towards the data.}
56+
57+
\item{\code{theme_minimal}}
58+
{A minimalistic theme with no background annotations.}
59+
60+
\item{\code{theme_classic}}
61+
{A classic-looking theme, with x and y axis lines and no gridlines.}
62+
63+
}
64+
}
65+
\examples{
66+
p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
67+
colour=factor(gear))) + facet_wrap(~am)
68+
69+
p
70+
p + theme_gray()
71+
p + theme_bw()
72+
p + theme_linedraw()
73+
p + theme_light()
74+
p + theme_minimal()
75+
p + theme_classic()
76+
}
77+

man/theme_bw.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

man/theme_classic.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

man/theme_grey.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

man/theme_light.Rd

Lines changed: 0 additions & 32 deletions
This file was deleted.

man/theme_linedraw.Rd

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)