First, I know about this answer: Mapping different states in R using face wrappers
But I am working with an sf library object.
It seems that facet_wrap(scales = "free") not available for objects built with geom_sf in ggplot2. I get this message:
Erreur: free scales are only supported with coord_cartesian() and coord_flip()
Is there any option I missed?
cowplot anyone solve the problem without being forced to use a cowplot (or any other mesh set)?
Indeed, here is an example. I would like to show different French regions separately in faces, but with their own x / y limits.
Result without scales = "free"
Scales are calculated taking into account the entire map.
FRA <- raster::getData(name = "GADM", country = "FRA", level = 1) FRA_sf <- st_as_sf(FRA) g <- ggplot(FRA_sf) + geom_sf() + facet_wrap(~NAME_1)

Result Using Cowplot
I need to use the ggplots list and then combine them. This is the target result. It is cleaner. But I also need a clean way to add legend. (I know that there may be a common legend, as in this other SO question: facet wrapper distorts state mappings in R )
g <- purrr::map(FRA_sf$NAME_1, function(x) { ggplot() + geom_sf(data = filter(FRA_sf, NAME_1 == x)) + guides(fill = FALSE) + ggtitle(x) }) g2 <- cowplot::plot_grid(plotlist = g)

r ggplot2 sf
Sebastien rochette
source share