I’m trying to get the same output with sf::st_as_sf()
that I get with the soon-to-be-deprecated ggplot2::fortify
:
<code>library(rworldmap)
library(sf)
library(ggplot2)
world_map <- rworldmap::getMap()
points <- ggplot2::fortify(world_map)
points_2 <- sf::st_as_sf(world_map, group=FALSE)
</code>
<code>library(rworldmap)
library(sf)
library(ggplot2)
world_map <- rworldmap::getMap()
points <- ggplot2::fortify(world_map)
points_2 <- sf::st_as_sf(world_map, group=FALSE)
</code>
library(rworldmap)
library(sf)
library(ggplot2)
world_map <- rworldmap::getMap()
points <- ggplot2::fortify(world_map)
points_2 <- sf::st_as_sf(world_map, group=FALSE)
returns a df with columns “long”, “lat”, “order”, “hole”, “piece”, “id”, and “group”, where multiple polygons for a country (=id) and their respective lat-long are a unique row (=group).
<code> long lat order hole piece id group
1 61.21082 35.65007 1 FALSE 1 Afghanistan Afghanistan.1
2 62.23065 35.27066 2 FALSE 1 Afghanistan Afghanistan.1
3 62.98466 35.40404 3 FALSE 1 Afghanistan Afghanistan.1
4 63.19354 35.85717 4 FALSE 1 Afghanistan Afghanistan.1
</code>
<code> long lat order hole piece id group
1 61.21082 35.65007 1 FALSE 1 Afghanistan Afghanistan.1
2 62.23065 35.27066 2 FALSE 1 Afghanistan Afghanistan.1
3 62.98466 35.40404 3 FALSE 1 Afghanistan Afghanistan.1
4 63.19354 35.85717 4 FALSE 1 Afghanistan Afghanistan.1
</code>
long lat order hole piece id group
1 61.21082 35.65007 1 FALSE 1 Afghanistan Afghanistan.1
2 62.23065 35.27066 2 FALSE 1 Afghanistan Afghanistan.1
3 62.98466 35.40404 3 FALSE 1 Afghanistan Afghanistan.1
4 63.19354 35.85717 4 FALSE 1 Afghanistan Afghanistan.1
st_as_sf
appears to keep the additional polygons in the list-column “geometry”. Is there an option for st_as_sf
to return the dataframe with the list flattened in the same way fortify
does?