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.
2
5
# '
3
6
# ' @param base_size base font size
4
7
# ' @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
8
54
theme_grey <- function (base_size = 12 , base_family = " " ) {
9
55
theme(
10
56
# Elements in this first block aren't used directly, but are inherited
@@ -59,15 +105,12 @@ theme_grey <- function(base_size = 12, base_family = "") {
59
105
complete = TRUE
60
106
)
61
107
}
108
+ # ' @export
109
+ # ' @rdname ggtheme
62
110
theme_gray <- theme_grey
63
111
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
69
112
# ' @export
70
- # ' @family themes
113
+ # ' @rdname ggtheme
71
114
theme_bw <- function (base_size = 12 , base_family = " " ) {
72
115
# Starts with theme_grey and then modify some parts
73
116
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
@@ -84,21 +127,8 @@ theme_bw <- function(base_size = 12, base_family = "") {
84
127
)
85
128
}
86
129
87
- # ' A theme with white background and black gridlines.
88
- # '
89
- # ' @param base_size base font size
90
- # ' @param base_family base font family
91
130
# ' @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
102
132
theme_linedraw <- function (base_size = 12 , base_family = " " ) {
103
133
# Starts with theme_grey and then modify some parts
104
134
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
@@ -116,44 +146,27 @@ theme_linedraw <- function(base_size = 12, base_family = "") {
116
146
)
117
147
}
118
148
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
123
149
# ' @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
134
151
theme_light <- function (base_size = 12 , base_family = " " ) {
135
152
# Starts with theme_grey and then modify some parts
136
153
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
137
154
theme(
138
- axis.ticks = element_line(colour = " grey50 " , size = 0.25 ),
155
+ axis.ticks = element_line(colour = " grey70 " , size = 0.25 ),
139
156
legend.key = element_rect(fill = " white" , colour = " grey50" , size = 0.25 ),
140
157
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 ),
145
162
strip.text.x = element_text(colour = " white" ),
146
163
strip.text.y = element_text(colour = " white" , angle = - 90 )
147
164
)
148
165
149
166
}
150
167
151
- # ' A minimalistic theme with no background annotations.
152
- # '
153
- # ' @param base_size base font size
154
- # ' @param base_family base font family
155
168
# ' @export
156
- # ' @family themes
169
+ # ' @rdname ggtheme
157
170
theme_minimal <- function (base_size = 12 , base_family = " " ) {
158
171
# Starts with theme_bw and then modify some parts
159
172
theme_bw(base_size = base_size , base_family = base_family ) %+ replace %
@@ -167,12 +180,8 @@ theme_minimal <- function(base_size = 12, base_family = "") {
167
180
)
168
181
}
169
182
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
174
183
# ' @export
175
- # ' @family themes
184
+ # ' @rdname ggtheme
176
185
theme_classic <- function (base_size = 12 , base_family = " " ){
177
186
theme_bw(base_size = base_size , base_family = base_family ) %+ replace %
178
187
theme(
0 commit comments