diff --git a/R/plot-render.R b/R/plot-render.R index 4492b16c68..5016ef6e20 100644 --- a/R/plot-render.R +++ b/R/plot-render.R @@ -279,6 +279,7 @@ table_add_tag <- function(table, label, theme) { if (location %in% c("plot", "panel")) { if (!is.numeric(position)) { hjust <- try_prop(element, "hjust", default = 0.5) + vjust <- try_prop(element, "vjust", default = 0.5) if (right || left) { x <- (1 - hjust) * width if (right) { @@ -288,7 +289,6 @@ table_add_tag <- function(table, label, theme) { x <- unit(hjust, "npc") } if (top || bottom) { - vjust <- try_prop(element, "vjust", default = 0.5) y <- (1 - vjust) * height if (top) { y <- unit(1, "npc") - y diff --git a/tests/testthat/test-labels.R b/tests/testthat/test-labels.R index d7eb22ba40..dfd933a62b 100644 --- a/tests/testthat/test-labels.R +++ b/tests/testthat/test-labels.R @@ -140,6 +140,23 @@ test_that("plot.tag.position rejects invalid input", { }) +test_that("left and right plot tags can be rendered inside plot regions", { + p <- ggplot(mtcars, aes(mpg, disp)) + geom_point() + labs(tag = "Fig. A)") + + for (position in c("left", "right")) { + for (location in c("plot", "panel")) { + expect_no_error( + ggplotGrob( + p + theme( + plot.tag.position = position, + plot.tag.location = location + ) + ) + ) + } + } +}) + test_that("position axis label hierarchy works as intended", { df <- data_frame(foo = c(1e1, 1e5), bar = c(0, 100))