Skip to content

Commit beb6e64

Browse files
committed
Add tests
1 parent 52eafac commit beb6e64

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed
Lines changed: 90 additions & 0 deletions
Loading
Lines changed: 90 additions & 0 deletions
Loading

tests/testthat/test-theme.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,36 @@ test_that("Strips can render custom elements", {
704704
theme(strip.text = element_test())
705705
expect_doppelganger("custom strip elements can render", plot)
706706
})
707+
708+
test_that("legend margins are correct when using relative key sizes", {
709+
710+
df <- data_frame(x = 1:3, y = 1:3, a = letters[1:3])
711+
p <- ggplot(df, aes(x, y, colour = x, shape = a)) +
712+
geom_point() +
713+
theme_test() +
714+
theme(
715+
legend.box.background = element_rect(colour = "blue", fill = NA),
716+
legend.background = element_rect(colour = "red", fill = NA)
717+
)
718+
719+
vertical <- p + guides(
720+
colour = guide_colourbar(barheight = unit(1, "null")),
721+
shape = guide_legend(keyheight = unit(1/3, "null"))
722+
) + theme(
723+
legend.box.margin = margin(t = 5, b = 10, unit = "mm"),
724+
legend.margin = margin(t = 10, b = 5, unit = "mm")
725+
)
726+
727+
expect_doppelganger("stretched vertical legends", vertical)
728+
729+
horizontal <- p + guides(
730+
colour = guide_colourbar(barwidth = unit(1, "null")),
731+
shape = guide_legend(keywidth = unit(1/3, "null"))
732+
) + theme(
733+
legend.position = "top",
734+
legend.box.margin = margin(l = 5, r = 10, unit = "mm"),
735+
legend.margin = margin(l = 10, r = 5, unit = "mm")
736+
)
737+
738+
expect_doppelganger("stretched horizontal legends", horizontal)
739+
})

0 commit comments

Comments
 (0)