tidyverse/ggplot2

Should default coords not replace existing coords?

Opened this issue · 0 comments

In the plot below, we add geom_sf() after specifying a coord. We get a warning that we're replacing the coord, and the intended projection is ignored. I'll note that geom_sf() comes with very own coord_sf(default = TRUE) in its return value.

library(ggplot2)

world <- rnaturalearth::ne_countries()

ggplot(world) +
  coord_sf(crs = "+proj=moll") +
  geom_sf()
#> Coordinate system already present.
#> ℹ Adding new coordinate system, which will replace the existing one.

I would have expected the following result:

ggplot(world) +
  geom_sf() +
  coord_sf(crs = "+proj=moll")

Created on 2025-08-22 with reprex v2.1.1

I propose that the update_ggplot() method for Coords only let default coords replace other default coords, but not let default coords replace non-default (user specified) coords.