69
69
theme_grey <- function (base_size = 11 , base_family = " " ,
70
70
base_line_size = base_size / 22 ,
71
71
base_rect_size = base_size / 22 ) {
72
+
73
+ # The half-line (base-fontsize / 2) sets up the basic vertical
74
+ # rhythm of the theme. Most margins will be set to this value.
75
+ # However, when we work with relative sizes, we may want to multiply
76
+ # `half_line` with the appropriate relative size. This applies in
77
+ # particular for axis tick sizes. And also, for axis ticks and
78
+ # axis titles, `half_size` is too large a distance, and we use `half_size/2`
79
+ # instead.
72
80
half_line <- base_size / 2
73
81
82
+ # Throughout the theme, we use three font sizes, `base_size` (`rel(1)`)
83
+ # for normal, `rel(0.8)` for small, and `rel(1.2)` for large.
84
+
74
85
theme(
75
86
# Elements in this first block aren't used directly, but are inherited
76
87
# by others
@@ -100,29 +111,29 @@ theme_grey <- function(base_size = 11, base_family = "",
100
111
axis.ticks = element_line(colour = " grey20" ),
101
112
axis.ticks.length = unit(half_line / 2 , " pt" ),
102
113
axis.title.x = element_text(
103
- margin = margin(t = half_line ),
114
+ margin = margin(t = half_line / 2 ),
104
115
vjust = 1
105
116
),
106
117
axis.title.x.top = element_text(
107
- margin = margin(b = half_line ),
118
+ margin = margin(b = half_line / 2 ),
108
119
vjust = 0
109
120
),
110
121
axis.title.y = element_text(
111
122
angle = 90 ,
112
- margin = margin(r = half_line ),
123
+ margin = margin(r = half_line / 2 ),
113
124
vjust = 1
114
125
),
115
126
axis.title.y.right = element_text(
116
127
angle = - 90 ,
117
- margin = margin(l = half_line ),
128
+ margin = margin(l = half_line / 2 ),
118
129
vjust = 0
119
130
),
120
131
121
132
legend.background = element_rect(colour = NA ),
122
- legend.spacing = unit(0.4 , " cm " ),
133
+ legend.spacing = unit(2 * half_line , " pt " ),
123
134
legend.spacing.x = NULL ,
124
135
legend.spacing.y = NULL ,
125
- legend.margin = margin(0.2 , 0.2 , 0.2 , 0.2 , " cm " ),
136
+ legend.margin = margin(half_line , half_line , half_line , half_line ),
126
137
legend.key = element_rect(fill = " grey95" , colour = " white" ),
127
138
legend.key.size = unit(1.2 , " lines" ),
128
139
legend.key.height = NULL ,
@@ -137,7 +148,7 @@ theme_grey <- function(base_size = 11, base_family = "",
137
148
legend.box = NULL ,
138
149
legend.box.margin = margin(0 , 0 , 0 , 0 , " cm" ),
139
150
legend.box.background = element_blank(),
140
- legend.box.spacing = unit(0.4 , " cm " ),
151
+ legend.box.spacing = unit(2 * half_line , " pt " ),
141
152
142
153
panel.background = element_rect(fill = " grey92" , colour = NA ),
143
154
panel.border = element_blank(),
@@ -152,31 +163,30 @@ theme_grey <- function(base_size = 11, base_family = "",
152
163
strip.text = element_text(
153
164
colour = " grey10" ,
154
165
size = rel(0.8 ),
155
- margin = margin(half_line , half_line , half_line , half_line )
166
+ margin = margin(0.8 * half_line , 0.8 * half_line , 0.8 * half_line , 0.8 * half_line )
156
167
),
157
168
strip.text.x = NULL ,
158
169
strip.text.y = element_text(angle = - 90 ),
159
170
strip.placement = " inside" ,
160
171
strip.placement.x = NULL ,
161
172
strip.placement.y = NULL ,
162
- strip.switch.pad.grid = unit(0.1 , " cm " ),
163
- strip.switch.pad.wrap = unit(0.1 , " cm " ),
173
+ strip.switch.pad.grid = unit(half_line / 2 , " pt " ),
174
+ strip.switch.pad.wrap = unit(half_line / 2 , " pt " ),
164
175
165
176
plot.background = element_rect(colour = " white" ),
166
- plot.title = element_text(
177
+ plot.title = element_text( # font size "large"
167
178
size = rel(1.2 ),
168
179
hjust = 0 , vjust = 1 ,
169
- margin = margin(b = half_line * 1.2 )
180
+ margin = margin(b = half_line )
170
181
),
171
- plot.subtitle = element_text(
172
- size = rel(0.9 ),
182
+ plot.subtitle = element_text( # font size "regular"
173
183
hjust = 0 , vjust = 1 ,
174
- margin = margin(b = half_line * 0.9 )
184
+ margin = margin(b = half_line )
175
185
),
176
- plot.caption = element_text(
177
- size = rel(0.9 ),
186
+ plot.caption = element_text( # font size "small"
187
+ size = rel(0.8 ),
178
188
hjust = 1 , vjust = 1 ,
179
- margin = margin(t = half_line * 0.9 )
189
+ margin = margin(t = half_line )
180
190
),
181
191
plot.margin = margin(half_line , half_line , half_line , half_line ),
182
192
@@ -248,7 +258,7 @@ theme_linedraw <- function(base_size = 11, base_family = "",
248
258
strip.text = element_text(
249
259
colour = " white" ,
250
260
size = rel(0.8 ),
251
- margin = margin(half_line , half_line , half_line , half_line )
261
+ margin = margin(0.8 * half_line , 0.8 * half_line , 0.8 * half_line , 0.8 * half_line )
252
262
),
253
263
254
264
complete = TRUE
@@ -290,7 +300,7 @@ theme_light <- function(base_size = 11, base_family = "",
290
300
strip.text = element_text(
291
301
colour = " white" ,
292
302
size = rel(0.8 ),
293
- margin = margin(half_line , half_line , half_line , half_line )
303
+ margin = margin(0.8 * half_line , 0.8 * half_line , 0.8 * half_line , 0.8 * half_line )
294
304
),
295
305
296
306
complete = TRUE
@@ -332,7 +342,7 @@ theme_dark <- function(base_size = 11, base_family = "",
332
342
strip.text = element_text(
333
343
colour = " grey90" ,
334
344
size = rel(0.8 ),
335
- margin = margin(half_line , half_line , half_line , half_line )
345
+ margin = margin(0.8 * half_line , 0.8 * half_line , 0.8 * half_line , 0.8 * half_line )
336
346
),
337
347
338
348
complete = TRUE
@@ -420,25 +430,24 @@ theme_void <- function(base_size = 11, base_family = "",
420
430
legend.text = element_text(size = rel(0.8 )),
421
431
legend.title = element_text(hjust = 0 ),
422
432
strip.text = element_text(size = rel(0.8 )),
423
- strip.switch.pad.grid = unit(0.1 , " cm " ),
424
- strip.switch.pad.wrap = unit(0.1 , " cm " ),
433
+ strip.switch.pad.grid = unit(half_line / 2 , " pt " ),
434
+ strip.switch.pad.wrap = unit(half_line / 2 , " pt " ),
425
435
panel.ontop = FALSE ,
426
436
panel.spacing = unit(half_line , " pt" ),
427
437
plot.margin = unit(c(0 , 0 , 0 , 0 ), " lines" ),
428
438
plot.title = element_text(
429
439
size = rel(1.2 ),
430
440
hjust = 0 , vjust = 1 ,
431
- margin = margin(t = half_line * 1.2 )
441
+ margin = margin(t = half_line )
432
442
),
433
443
plot.subtitle = element_text(
434
- size = rel(0.9 ),
435
444
hjust = 0 , vjust = 1 ,
436
- margin = margin(t = half_line * 0.9 )
445
+ margin = margin(t = half_line )
437
446
),
438
447
plot.caption = element_text(
439
- size = rel(0.9 ),
448
+ size = rel(0.8 ),
440
449
hjust = 1 , vjust = 1 ,
441
- margin = margin(t = half_line * 0.9 )
450
+ margin = margin(t = half_line )
442
451
),
443
452
444
453
complete = TRUE
@@ -480,26 +489,26 @@ theme_test <- function(base_size = 11, base_family = "",
480
489
axis.ticks = element_line(colour = " grey20" ),
481
490
axis.ticks.length = unit(half_line / 2 , " pt" ),
482
491
axis.title.x = element_text(
483
- margin = margin(t = half_line ),
492
+ margin = margin(t = half_line / 2 ),
484
493
vjust = 1
485
494
),
486
495
axis.title.x.top = element_text(
487
- margin = margin(b = half_line ),
496
+ margin = margin(b = half_line / 2 ),
488
497
vjust = 0
489
498
),
490
499
axis.title.y = element_text(
491
500
angle = 90 ,
492
- margin = margin(r = half_line ),
501
+ margin = margin(r = half_line / 2 ),
493
502
vjust = 1
494
503
),
495
504
axis.title.y.right = element_text(
496
505
angle = - 90 ,
497
- margin = margin(l = half_line ),
506
+ margin = margin(l = half_line / 2 ),
498
507
vjust = 0
499
508
),
500
509
501
510
legend.background = element_rect(colour = NA ),
502
- legend.spacing = unit(0.4 , " cm " ),
511
+ legend.spacing = unit(2 * half_line , " pt " ),
503
512
legend.spacing.x = NULL ,
504
513
legend.spacing.y = NULL ,
505
514
legend.margin = margin(0 , 0 , 0 , 0 , " cm" ),
@@ -517,7 +526,7 @@ theme_test <- function(base_size = 11, base_family = "",
517
526
legend.box = NULL ,
518
527
legend.box.margin = margin(0 , 0 , 0 , 0 , " cm" ),
519
528
legend.box.background = element_blank(),
520
- legend.box.spacing = unit(0.4 , " cm " ),
529
+ legend.box.spacing = unit(2 * half_line , " pt " ),
521
530
522
531
panel.background = element_rect(fill = " white" , colour = NA ),
523
532
panel.border = element_rect(fill = NA , colour = " grey20" ),
@@ -532,31 +541,30 @@ theme_test <- function(base_size = 11, base_family = "",
532
541
strip.text = element_text(
533
542
colour = " grey10" ,
534
543
size = rel(0.8 ),
535
- margin = margin(half_line , half_line , half_line , half_line )
544
+ margin = margin(0.8 * half_line , 0.8 * half_line , 0.8 * half_line , 0.8 * half_line )
536
545
),
537
546
strip.text.x = NULL ,
538
547
strip.text.y = element_text(angle = - 90 ),
539
548
strip.placement = " inside" ,
540
549
strip.placement.x = NULL ,
541
550
strip.placement.y = NULL ,
542
- strip.switch.pad.grid = unit(0.1 , " cm " ),
543
- strip.switch.pad.wrap = unit(0.1 , " cm " ),
551
+ strip.switch.pad.grid = unit(half_line / 2 , " pt " ),
552
+ strip.switch.pad.wrap = unit(half_line / 2 , " pt " ),
544
553
545
554
plot.background = element_rect(colour = " white" ),
546
555
plot.title = element_text(
547
556
size = rel(1.2 ),
548
557
hjust = 0 , vjust = 1 ,
549
- margin = margin(b = half_line * 1.2 )
558
+ margin = margin(b = half_line )
550
559
),
551
560
plot.subtitle = element_text(
552
- size = rel(0.9 ),
553
561
hjust = 0 , vjust = 1 ,
554
- margin = margin(b = half_line * 0.9 )
562
+ margin = margin(b = half_line )
555
563
),
556
564
plot.caption = element_text(
557
- size = rel(0.9 ),
565
+ size = rel(0.8 ),
558
566
hjust = 1 , vjust = 1 ,
559
- margin = margin(t = half_line * 0.9 )
567
+ margin = margin(t = half_line )
560
568
),
561
569
plot.margin = margin(half_line , half_line , half_line , half_line ),
562
570
0 commit comments