Skip to content

geom_tile() not square when saving high res map (may be a more fundamental R graphics issue) #6029

Closed as not planned
@jack-davison

Description

@jack-davison

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:

image

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.

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions