File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -415,14 +415,14 @@ theme <- function(line,
415
415
416
416
417
417
# Combine plot defaults with current theme to get complete theme for a plot
418
- plot_theme <- function (x ) {
418
+ plot_theme <- function (x , default_theme = theme_get() ) {
419
419
complete <- attr(x $ theme , " complete" )
420
420
if (is.null(complete )) {
421
- theme_get()
421
+ default_theme
422
422
} else if (complete ) {
423
423
x $ theme
424
424
} else {
425
- defaults(x $ theme , theme_get() )
425
+ defaults(x $ theme , default_theme )
426
426
}
427
427
}
428
428
Original file line number Diff line number Diff line change @@ -163,6 +163,20 @@ test_that("Complete and non-complete themes interact correctly with ggplot objec
163
163
expect_false(attr(p $ plot $ theme , " complete" ))
164
164
expect_equal(p $ plot $ theme $ text $ colour , " red" )
165
165
expect_equal(p $ plot $ theme $ text $ face , " italic" )
166
+
167
+ # The final calculated plot theme should not blend a complete theme
168
+ # with the default theme
169
+ default_theme <- theme_gray() + theme(axis.text.x = element_text(colour = " red" ))
170
+
171
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme_void(), default_theme )
172
+ expect_null(ptheme $ axis.text.x )
173
+
174
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme_gray(), default_theme )
175
+ expect_true(is.null(ptheme $ axis.text.x $ colour ) || ptheme $ axis.text.x $ colour != " red" )
176
+
177
+ ptheme <- plot_theme(qplot(1 : 3 , 1 : 3 ) + theme(axis.text.y = element_text(colour = " blue" )), default_theme )
178
+ expect_equal(ptheme $ axis.text.x $ colour , " red" )
179
+ expect_equal(ptheme $ axis.text.y $ colour , " blue" )
166
180
})
167
181
168
182
test_that(" theme(validate=FALSE) means do not validate_element" , {
You can’t perform that action at this time.
0 commit comments