-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as not planned
Closed as not planned
Copy link
Description
Hello!
Facet plots in ggplot2
using spatial coordinates (coord_sf
) will force the sharing of x and y axis ranges(?). facet_wrap
and facet_grid
both behave the same case.
I suspect this issue is complicated due to the potential existence of a fixed aspect ratio in coord_sf
. This also makes it extremely difficult to use patchwork
to stitch together multiple spatial results.
This will result in a very strange spatial data layout:
library(tidyverse)
library(rnaturalearthdata)
library(rnaturalearth)
#>
#> Attaching package: 'rnaturalearth'
#> The following object is masked from 'package:rnaturalearthdata':
#>
#> countries110
world <- ne_countries()
#plot(world$geometry)
data <- world |>
filter(name %in% c("Japan", "Austria", "Australia"))
d1 <- data |> mutate(value = 1)
d2 <- data |> mutate(value = 2)
d3 <- data |> mutate(value = 3)
dt <- rbind(d1, d2, d3)
ggplot() +
geom_sf(data = dt, aes(fill = value), color = "black") +
scale_fill_viridis_c() +
facet_grid(value ~ name) +
theme_minimal()
ggplot() +
geom_sf(data = dt, aes(fill = value), color = "black") +
scale_fill_viridis_c() +
facet_wrap(c("value", "name")) +
theme_minimal()
ggplot() +
geom_sf(data = dt, aes(fill = value), color = "black") +
scale_fill_viridis_c() +
facet_wrap(c("value", "name"), scales = 'free_x') +
theme_minimal()
> Error in `draw_panels()`:
! `facet_wrap()` can't use free scales with `coord_sf()`.
Run `rlang::last_trace()` to see where the error occurred.
Created on 2025-10-01 with reprex v2.1.1
Best wishes,
Hu
Metadata
Metadata
Assignees
Labels
No labels