Description
A colleague is encountering an issue saving a large geographical heatmap made using geom_tile()
; when saving this quite large, high-res plot as a PNG image the squares produced by geom_tile()
aren't square!
reprex:
set.seed(123)
testdf <-
expand.grid(
x = seq(500, 655500, 1000),
y = seq(500, 655500, 1000)
)
testdf |>
dplyr::mutate(col = sample(letters[1:4], replace = TRUE, nrow(testdf))) |>
ggplot(aes(x, y, fill = col)) +
geom_tile()
ggsave("testrprex.png", dpi = 300, width = 15, height = 15)
This produces the below - annotations mine:
We believe this is to do with how R/ggplot2 interpolates between rectangles as when antialiasing is turned off (snap_rect = FALSE
) the grid is a lot more regular, but has a sort of grid artefact where you can see horizontal/vertical lines - almost like a mosaic.
Is there a fix to avoid these non-square tiles when saving without getting the gridlines? As it is a spatial heatmap, it's important for the client to be able to zoom in quite close to each square, and they may question why some are rectangular!
Thanks very much