MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #15812] par(bg='transparent') not affecting svg #5350

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

Created attachment 1607 [details] test.svg with white background instead of expected transparent background

Setting background to transparent via par(bg='transparent') seems to not trigger a transparent background of svg devices, although it works for other colors with svg devices and for other devices with transparent.

How to reproduce:

# works fine png('test.png'); par(bg='transparent'); plot(1:10); dev.off()

# works fine too svg('test.svg'); par(bg='blue'); plot(1:10); dev.off()

# white background added? svg('test.svg'); par(bg='transparent'); plot(1:10); dev.off()


METADATA

MichaelChirico commented 4 years ago

Workaround: stating the bg argument directly in the graphics device to transparent seems to work for all devices:

png('test.png', bg='transparent'); plot(1:10); dev.off() svg('test.svg', bg='transparent'); plot(1:10); dev.off()

As far as I understand setting par(bg='transparent') should (but does not) work for png as well as for svg.

Best


METADATA

MichaelChirico commented 4 years ago

This is reproducible in R 3.6.2.

When opening the svg device with default bg="white" and then modifying the background via par(bg='transparent') it still adds

to the svg file, i.e. a white rectangle. Similary, if we open the device with svg(..., bg="blue") and then set par(bg="transparent") we still get a blue rectangle with rgb(0%,0%,100%). Thus, setting par(bg="transparent") seems to have no effect on the svg device.

In contrast, when opening the svg device with an initially transparent background via svg(..., bg='transparent') no element is generated as desired.

Interestingly, the svglite device provided by the svglite package has the same problem. Setting par(bg="transparent") after opening the graphics device has no effect.


METADATA

  • Comment author - Sebastian Meyer
  • Timestamp - 2020-01-16 15:19:07 UTC