@@ -111,7 +111,7 @@ theme_grey <- function(base_size = 11, base_family = "",
111
111
# Throughout the theme, we use three font sizes, `base_size` (`rel(1)`)
112
112
# for normal, `rel(0.8)` for small, and `rel(1.2)` for large.
113
113
114
- theme(
114
+ t <- theme(
115
115
# Elements in this first block aren't used directly, but are inherited
116
116
# by others
117
117
line = element_line(
@@ -234,6 +234,9 @@ theme_grey <- function(base_size = 11, base_family = "",
234
234
235
235
complete = TRUE
236
236
)
237
+
238
+ # make sure all elements are set to NULL if not explicitly defined
239
+ theme_all_null() %+ replace % t
237
240
}
238
241
# ' @export
239
242
# ' @rdname ggtheme
@@ -455,7 +458,7 @@ theme_void <- function(base_size = 11, base_family = "",
455
458
half_line <- base_size / 2
456
459
457
460
# Only keep indispensable text: legend and plot titles
458
- theme(
461
+ t <- theme(
459
462
line = element_blank(),
460
463
rect = element_blank(),
461
464
text = element_text(
@@ -508,6 +511,9 @@ theme_void <- function(base_size = 11, base_family = "",
508
511
509
512
complete = TRUE
510
513
)
514
+
515
+ # make sure all elements are set to NULL if not explicitly defined
516
+ theme_all_null() %+ replace % t
511
517
}
512
518
513
519
@@ -518,7 +524,7 @@ theme_test <- function(base_size = 11, base_family = "",
518
524
base_rect_size = base_size / 22 ) {
519
525
half_line <- base_size / 2
520
526
521
- theme(
527
+ t <- theme(
522
528
line = element_line(
523
529
colour = " black" , size = base_line_size ,
524
530
linetype = 1 , lineend = " butt"
@@ -639,4 +645,19 @@ theme_test <- function(base_size = 11, base_family = "",
639
645
640
646
complete = TRUE
641
647
)
648
+
649
+ # make sure all elements are set to NULL if not explicitly defined
650
+ theme_all_null() %+ replace % t
651
+ }
652
+
653
+ theme_all_null <- function () {
654
+ # set all elements in the element tree to NULL
655
+ elements <- sapply(
656
+ names(ggplot_global $ element_tree ),
657
+ function (x ) NULL ,
658
+ simplify = FALSE , USE.NAMES = TRUE
659
+ )
660
+
661
+ args <- c(elements , list (complete = TRUE ))
662
+ do.call(theme , args )
642
663
}
0 commit comments