@@ -150,142 +150,145 @@ theme_gray <- theme_grey
150
150
151
151
# ' @export
152
152
# ' @rdname ggtheme
153
- theme_bw <- function (base_size = 12 , base_family = " " ) {
153
+ theme_bw <- function (base_size = 11 , base_family = " " ) {
154
154
# Starts with theme_grey and then modify some parts
155
155
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
156
156
theme(
157
- axis.text = element_text(size = rel(0.8 )),
158
- axis.ticks = element_line(colour = " black" ),
159
- legend.key = element_rect(colour = " grey80" ),
160
- panel.background = element_rect(fill = " white" , colour = NA ),
161
- panel.border = element_rect(fill = NA , colour = " grey50" ),
162
- panel.grid.major = element_line(colour = " grey90" , size = 0.2 ),
163
- panel.grid.minor = element_line(colour = " grey98" , size = 0.5 ),
164
- strip.background = element_rect(fill = " grey80" , colour = " grey50" , size = 0.2 )
157
+ # white background and dark border
158
+ panel.background = element_rect(fill = " white" , colour = NA ),
159
+ panel.border = element_rect(fill = NA , colour = " grey20" ),
160
+ # make gridlines dark, same contrast with white as in theme_grey
161
+ panel.grid.major = element_line(colour = " grey92" ),
162
+ panel.grid.minor = element_line(colour = " grey92" , size = 0.25 ),
163
+ # contour strips to match panel contour
164
+ strip.background = element_rect(fill = " grey85" , colour = " grey20" ),
165
+ # match legend key to background
166
+ legend.key = element_rect(fill = " white" , colour = NA )
165
167
)
166
168
}
167
169
168
170
# ' @export
169
171
# ' @rdname ggtheme
170
- theme_linedraw <- function (base_size = 12 , base_family = " " ) {
171
- half_line <- base_size / 2
172
+ theme_linedraw <- function (base_size = 11 , base_family = " " ) {
173
+ # Starts with theme_bw and then modify some parts
174
+ # = replace all greys with pure black or white
175
+ theme_bw(base_size = base_size , base_family = base_family ) %+ replace %
176
+ theme(
177
+ # black text and ticks on the axes
178
+ axis.text = element_text(colour = " black" , size = rel(0.8 )),
179
+ axis.ticks = element_line(colour = " black" , size = 0.25 ),
180
+ # NB: match the *visual* thickness of axis ticks to the panel border
181
+ # 0.5 clipped looks like 0.25
182
+
183
+ # pure black panel border and grid lines, but thinner
184
+ panel.border = element_rect(fill = NA , colour = " black" , size = 0.5 ),
185
+ panel.grid.major = element_line(colour = " black" , size = 0.05 ),
186
+ panel.grid.minor = element_line(colour = " black" , size = 0.025 ),
187
+
188
+ # strips with black background and white text
189
+ strip.background = element_rect(fill = " black" ),
190
+ strip.text = element_text(colour = " white" , size = rel(0.8 ))
191
+ )
192
+ }
193
+
194
+ # ' @export
195
+ # ' @rdname ggtheme
196
+ theme_light <- function (base_size = 11 , base_family = " " ) {
172
197
# Starts with theme_grey and then modify some parts
173
198
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
174
199
theme(
175
- axis.text = element_text( colour = " black " , size = rel( 0.8 )),
176
- axis.ticks = element_line( colour = " black " , size = 0.25 ),
177
- legend.key = element_rect(colour = " black " , size = 0.25 ),
178
- panel.background = element_rect( fill = " white " , colour = NA ),
179
- panel.border = element_rect( fill = NA , colour = " black " , size = 0.5 ),
180
- panel.grid.major = element_line(colour = " black " , size = 0.05 ),
181
- panel.grid.minor = element_line(colour = " black " , size = 0.01 ),
182
- strip.background = element_rect( fill = " black " , colour = NA ),
183
- strip.text.x = element_text(
184
- colour = " white " ,
185
- margin = margin( t = half_line , b = half_line )
186
- ),
187
- strip.text.y = element_text(
188
- colour = " white " ,
189
- angle = 90 ,
190
- margin = margin( l = half_line , r = half_line )
191
- )
200
+ # white panel with light grey border
201
+ panel.background = element_rect( fill = " white " , colour = NA ),
202
+ panel.border = element_rect(fill = NA , colour = " grey70 " , size = 0.5 ),
203
+ # light grey, thinner gridlines
204
+ # => make them slightly darker to keep acceptable contrast
205
+ panel.grid.major = element_line(colour = " grey87 " , size = 0.25 ),
206
+ panel.grid.minor = element_line(colour = " grey87 " , size = 0.125 ),
207
+
208
+ # match axes ticks thickness to gridlines and colour to panel border
209
+ axis.ticks = element_line( colour = " grey70 " , size = 0.25 ) ,
210
+
211
+ # match legend key to panel.background
212
+ legend.key = element_rect( fill = " white " , colour = NA ),
213
+
214
+ # dark strips with light text (inverse contrast compared to theme_grey)
215
+ strip.background = element_rect( fill = " grey70 " , colour = NA ),
216
+ strip.text = element_text( colour = " white " , size = rel( 0.8 ) )
192
217
)
218
+
193
219
}
194
220
195
221
# ' @export
196
222
# ' @rdname ggtheme
197
- theme_light <- function (base_size = 12 , base_family = " " ) {
198
- half_line <- base_size / 2
223
+ theme_dark <- function (base_size = 11 , base_family = " " ) {
199
224
# Starts with theme_grey and then modify some parts
200
225
theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
201
226
theme(
202
- axis.ticks = element_line(colour = " grey70" , size = 0.25 ),
203
- legend.key = element_rect(fill = " white" , colour = " grey50" , size = 0.25 ),
204
- panel.background = element_rect(fill = " white" , colour = NA ),
205
- panel.border = element_rect(fill = NA , colour = " grey70" , size = 0.5 ),
206
- panel.grid.major = element_line(colour = " grey85" , size = 0.25 ),
207
- panel.grid.minor = element_line(colour = " grey93" , size = 0.125 ),
208
- strip.background = element_rect(fill = " grey70" , colour = NA ),
209
- strip.text.x = element_text(
210
- colour = " white" ,
211
- margin = margin(t = half_line , b = half_line )
212
- ),
213
- strip.text.y = element_text(
214
- colour = " white" ,
215
- angle = - 90 ,
216
- margin = margin(l = half_line , r = half_line )
217
- )
218
- )
227
+ # dark panel
228
+ panel.background = element_rect(fill = " grey50" , colour = NA ),
229
+ # inverse grid lines contrast compared to theme_grey
230
+ # make them thinner and try to keep the same visual contrast as in theme_light
231
+ panel.grid.major = element_line(colour = " grey42" , size = 0.25 ),
232
+ panel.grid.minor = element_line(colour = " grey42" , size = 0.125 ),
233
+
234
+ # match axes ticks thickness to gridlines
235
+ axis.ticks = element_line(colour = " grey20" , size = 0.25 ),
236
+
237
+ # match legend key to panel.background
238
+ legend.key = element_rect(fill = " grey50" , colour = NA ),
219
239
240
+ # dark strips with light text (inverse contrast compared to theme_grey)
241
+ strip.background = element_rect(fill = " grey15" , colour = NA ),
242
+ strip.text = element_text(colour = " grey90" , size = rel(0.8 ))
243
+ )
220
244
}
221
245
222
246
# ' @export
223
247
# ' @rdname ggtheme
224
- theme_minimal <- function (base_size = 12 , base_family = " " ) {
225
- # Starts with theme_bw and then modify some parts
248
+ theme_minimal <- function (base_size = 11 , base_family = " " ) {
249
+ # Starts with theme_bw and remove most parts
226
250
theme_bw(base_size = base_size , base_family = base_family ) %+ replace %
227
251
theme(
252
+ axis.ticks.x = element_blank(),
253
+ axis.ticks.y = element_blank(),
228
254
legend.background = element_blank(),
229
255
legend.key = element_blank(),
230
256
panel.background = element_blank(),
231
257
panel.border = element_blank(),
232
258
strip.background = element_blank(),
233
- plot.background = element_blank(),
234
- axis.ticks = element_line(),
235
- axis.ticks.x = element_blank(),
236
- axis.ticks.y = element_blank(),
237
- axis.ticks.length = unit(1 , " lines" )
259
+ plot.background = element_blank()
238
260
)
239
261
}
240
262
241
263
# ' @export
242
264
# ' @rdname ggtheme
243
- theme_classic <- function (base_size = 12 , base_family = " " ){
265
+ theme_classic <- function (base_size = 11 , base_family = " " ){
244
266
theme_bw(base_size = base_size , base_family = base_family ) %+ replace %
245
267
theme(
268
+ # no background and no grid
246
269
panel.border = element_blank(),
247
- axis.line = element_line(colour = " black" ),
248
- panel.grid.major = element_line(),
249
- panel.grid.major.x = element_blank(),
250
- panel.grid.major.y = element_blank(),
251
- panel.grid.minor = element_line(),
252
- panel.grid.minor.x = element_blank(),
253
- panel.grid.minor.y = element_blank(),
254
- strip.background = element_rect(colour = " black" , size = 0.5 ),
255
- legend.key = element_blank()
256
- )
257
- }
270
+ panel.grid.major = element_blank(),
271
+ panel.grid.minor = element_blank(),
258
272
259
- # ' @export
260
- # ' @rdname ggtheme
261
- theme_dark <- function (base_size = 12 , base_family = " " ) {
262
- half_line <- base_size / 2
263
- # Starts with theme_grey and then modify some parts
264
- theme_grey(base_size = base_size , base_family = base_family ) %+ replace %
265
- theme(
266
- axis.ticks = element_line(colour = " grey40" , size = 0.25 ),
267
- legend.key = element_rect(fill = " grey50" , colour = " grey40" , size = 0.25 ),
268
- panel.background = element_rect(fill = " grey50" , colour = NA ),
269
- panel.grid.major = element_line(colour = " grey40" , size = 0.25 ),
270
- panel.grid.minor = element_line(colour = " grey45" , size = 0.125 ),
271
- strip.background = element_rect(fill = " grey20" , colour = NA ),
272
- strip.text.x = element_text(
273
- colour = " white" ,
274
- margin = margin(t = half_line , b = half_line )
275
- ),
276
- strip.text.y = element_text(
277
- colour = " white" ,
278
- angle = - 90 ,
279
- margin = margin(l = half_line , r = half_line )
280
- )
273
+ # show axes
274
+ axis.line.x = element_line(colour = " black" , size = 0.5 ),
275
+ axis.line.y = element_line(colour = " black" , size = 0.5 ),
276
+
277
+ # match legend key to panel.background
278
+ legend.key = element_blank(),
279
+
280
+ # simple, black and white strips
281
+ strip.background = element_rect(fill = " white" , colour = " black" , size = 1 )
282
+ # NB: size is 1 but clipped, it looks like the 0.5 of the axes
281
283
)
282
284
}
283
285
284
286
# ' @export
285
287
# ' @rdname ggtheme
286
- theme_void <- function (base_size = 12 , base_family = " " ) {
288
+ theme_void <- function (base_size = 11 , base_family = " " ) {
287
289
theme(
288
- # Use only inherited elements and make everything blank
290
+ # Use only inherited elements and make almost everything blank
291
+ # Only keep indispensable text
289
292
line = element_blank(),
290
293
rect = element_blank(),
291
294
text = element_text(
@@ -294,14 +297,14 @@ theme_void <- function(base_size = 12, base_family = "") {
294
297
lineheight = 0.9 , hjust = 0.5 , vjust = 0.5 , angle = 0 ,
295
298
margin = margin(), debug = FALSE
296
299
),
297
- plot.margin = unit(c(0 , 0 , 0 , 0 ), " lines" ),
298
300
axis.text.x = element_blank(),
299
301
axis.text.y = element_blank(),
300
302
axis.title.x = element_blank(),
301
303
axis.title.y = element_blank(),
302
304
legend.text = element_text(size = rel(0.8 )),
303
- legend.title = element_blank( ),
305
+ legend.title = element_text( hjust = 0 ),
304
306
strip.text = element_text(size = rel(0.8 )),
307
+ plot.margin = unit(c(0 , 0 , 0 , 0 ), " lines" ),
305
308
306
309
complete = TRUE
307
310
)
0 commit comments