0

I have this map data with gdp and country group data. Instead of the whole world on a map I want to make a panel for each country group. This is head() of the map data.

> head(my_map)
Simple feature collection with 6 features and 2 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -73.41544 ymin: -55.25 xmax: 75.15803 ymax: 42.68825
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
           gdp   country_group                       geometry
1  19362969582   Southern Asia MULTIPOLYGON (((61.21082 35...
2 105750987619   Middle Africa MULTIPOLYGON (((16.32653 -5...
3  15058879129 Southern Europe MULTIPOLYGON (((20.59025 41...
4 414178897209    Western Asia MULTIPOLYGON (((51.57952 24...
5 518475134084   South America MULTIPOLYGON (((-65.5 -55.2...
6  12433089919    Western Asia MULTIPOLYGON (((43.58275 41...
> 

This is the code I use:

my_map %>%
  ggplot(aes(fill = gdp)) +
  geom_sf() +
  scale_fill_gradient2() +
  theme_bw(base_size = 10) +
  facet_grid(~country_group, scales = "free")
  #facet_wrap(~country_group, scales = "free") 

But I get the error:

Error: coord_sf doesn't support free scales

I have tried both facet_grid and facet_wrap, but none works. Any tips?

Robin Lindström
  • 622
  • 4
  • 15

0 Answers0