When I rotate an imported png image, a white background is added around the “box” the image is in. This happens on windows machine (R 4.3.2) but not on Mac (R 4.2.2). Both have ‘png’ version 0.1.8.
This is the code run on both machines (loading two basic blue and red colored rectangles):
library(png)
plot.new()
plot.window(xlim = c(0 , 10), ylim = c(0, 10))
# blue background
blue.rect <- readPNG("Desktop/rastr_test/blue.png")
rasterImage(blue.rect, 0, 0, 10, 10)
# red boxe
red.rect <- readPNG("Desktop/rastr_test/red.png")
# not rotated
rasterImage(red.rect, xleft = 1, ybottom = 4, xright = 3, ytop = 6, angle = 0)
# rotated
rasterImage(red.rect, xleft = 6, ybottom = 4, xright = 8, ytop = 6, angle = 45)
Here is the result on Mac (expected):
enter image description here
Here is the result on Windows:
enter image description here
How can I remove the white background on Windows?