Skip to content

Commit 6a4472d

Browse files
committed
Specify title, subtitle and caption texts
This makes theme_void have a similar overall layout to other themes. And move tests to separate function.
1 parent ea873b2 commit 6a4472d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

R/theme-defaults.r

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,18 @@ theme_void <- function(base_size = 11, base_family = "",
400400
panel.ontop = FALSE,
401401
panel.spacing = unit(half_line, "pt"),
402402
plot.margin = unit(c(0, 0, 0, 0), "lines"),
403+
plot.title = element_text(
404+
size = rel(1.2),
405+
hjust = 0, vjust = 1,
406+
margin = margin(t = half_line * 1.2)),
407+
plot.subtitle = element_text(
408+
size = rel(0.9),
409+
hjust = 0, vjust = 1,
410+
margin = margin(t = half_line * 0.9)),
411+
plot.caption = element_text(
412+
size = rel(0.9),
413+
hjust = 1, vjust = 1,
414+
margin = margin(t = half_line * 0.9)),
403415

404416
complete = TRUE
405417
)

tests/testthat/test-theme.r

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,6 @@ test_that("Complete and non-complete themes interact correctly with ggplot objec
164164
expect_equal(p$plot$theme$text$colour, "red")
165165
expect_equal(p$plot$theme$text$face, "italic")
166166

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")
180167
})
181168

182169
test_that("theme(validate=FALSE) means do not validate_element", {
@@ -238,6 +225,19 @@ test_that("Elements can be merged", {
238225
)
239226
})
240227

228+
test_that("Final calculated plot theme should not blend a complete theme with the default theme", {
229+
default_theme <- theme_gray() + theme(axis.text.x = element_text(colour = "red"))
230+
231+
ptheme <- plot_theme(qplot(1:3, 1:3) + theme_void(), default_theme)
232+
expect_null(ptheme$axis.text.x)
233+
234+
ptheme <- plot_theme(qplot(1:3, 1:3) + theme_gray(), default_theme)
235+
expect_true(is.null(ptheme$axis.text.x$colour) || ptheme$axis.text.x$colour != "red")
236+
237+
ptheme <- plot_theme(qplot(1:3, 1:3) + theme(axis.text.y = element_text(colour = "blue")), default_theme)
238+
expect_equal(ptheme$axis.text.x$colour, "red")
239+
expect_equal(ptheme$axis.text.y$colour, "blue")
240+
})
241241

242242
# Visual tests ------------------------------------------------------------
243243

0 commit comments

Comments
 (0)