Skip to content

ggsave to svg fails for certain themes #4212

Closed

Description

@geotheory

ggsave to svg operation is failing when certain themes are used:

require(ggplot2)
#> Loading required package: ggplot2
p = qplot(Sepal.Length, data=iris, geom='density') + theme_void()
ggsave(p, filename = 'test.svg', w=8, h=6)
#> Error in svglite_(file, bg, width, height, pointsize, standalone, aliases): Expecting a single string value: [type=NULL; extent=0].

I've tested {ggplot} and {ggthemes} and the following show this error:

  • ggplot::theme_void
  • ggplot::theme_minimal
  • ggthemes::theme_map
  • ggthemes::theme_tufte
  • ggthemes::theme_solid

I'm running macOS 10.15.5, R 4.0.2, ggplot 3.3.2.9000.

Activity

  1. added
    bug
    on Sep 30, 2020
  2. karawoo commented on Sep 30, 2020

    @karawoo
    Member

    Thanks for filing, this looks like a consequence of #4164. I guess our approach to that feature needs a bit more nuance to handle themes whose background is null or blank

    theme_void()$plot.background
    #> NULL
    theme_minimal()$plot.background
    #> list()
    #> - attr(*, "class")= chr [1:2] "element_blank" "element"

    A workaround is to explicitly set the background color in your call to ggsave()

    ggsave(p, filename = 'test.svg', w = 8, h = 6, bg = "white")
  3. self-assigned this
    on Sep 30, 2020
  4. geotheory commented on Oct 29, 2020

    @geotheory
    Author

    Thanks @karawoo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions