Skip to content

geom_sf() and facet_*(..., scales="free"): plot aspect ratio #2651

@adrfantini

Description

@adrfantini

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorcoord 🗺️

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions