geom_sf() and facet_*(..., scales="free"): plot aspect ratio · Issue #2651 · tidyverse/ggplot2 (original) (raw)

Setting scales="free" in facet_* resets geom_sf aspect ratio handling, even if not necessary. See reprex below.

library(ggplot2) library(dplyr) library(sf) nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) %>% mutate(dummy=1) nc2 <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) %>% mutate(dummy=2) #Correct form factor for the plot: ggplot(rbind(nc, nc2)) + geom_sf(aes(fill = AREA)) + facet_wrap(dummy) #Adding scales="free" causes the plot to be warped: ggplot(rbind(nc, nc2)) + geom_sf(aes(fill = AREA)) + facet_wrap(dummy, scales="free")

Without scales="free":
spectacle twz916
With scales="free":
spectacle hcf916

scales="free" should allow facets to have different ranges without altering the plot aspect ratio.