Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/save.r
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ggsave <- function(filename, plot = last_plot(),
filename <- file.path(path, filename)
}
if (is_null(bg)) {
bg <- calc_element("plot.background", plot_theme(plot))$fill
bg <- calc_element("plot.background", plot_theme(plot))$fill %||% "transparent"
}
old_dev <- grDevices::dev.cur()
dev(filename = filename, width = dim[1], height = dim[2], bg = bg, ...)
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-ggsave.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ test_that("ggsave uses theme background as image background", {
expect_true(grepl("fill: #00CCCC", bg))
})

test_that("ggsave can handle blank background", {
skip_if_not_installed("xml2")

path <- tempfile()
on.exit(unlink(path))
p <- ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
theme(plot.background = element_blank())
ggsave(path, p, device = "svg", width = 5, height = 5)
img <- xml2::read_xml(path)
bg <- as.character(xml2::xml_find_first(img, xpath = "d1:rect/@style"))
expect_true(grepl("fill: none", bg))
})


# plot_dim ---------------------------------------------------------------

test_that("guesses and informs if dim not specified", {
Expand Down