Open mariarrt94 opened 10 months ago
Looks like the ne_countries
function using the latest version of the rnaturalearth
package makes an sf
polygon. The below figures assume world_sp
is sp, not sf -- so fixed this by converting world_sp
to an sp
object.
In short, I changed:
world_sp <- ne_countries(type = "countries", scale=50)
to
world_sp <- ne_countries(type = "countries", scale=50) %>% as("Spatial")
https://github.com/dime-worldbank/big-data-poverty-estimation/blob/5b69a88c6e5bbf8ccdd699d4acd3ffd4623d9f49/DataWork/05_figures_tables_global/main/levels_2_global_scatterplot_average_map.R#L206
Changed this to:
world_sp <- world_sp %>% dplyr::select(name, continent) %>% dplyr::rename(country_name = name) %>% dplyr::mutate(country_name = case_when( country_name %in% "Dem. Rep. Congo" ~ "Congo - Kinshasa", country_name %in% "Côte d'Ivoire" ~ "Côte d’Ivoire", country_name %in% "Dominican Rep." ~ "Dominican Republic", country_name %in% "Swaziland" ~ "Eswatini", country_name %in% "Myanmar" ~ "Myanmar (Burma)", TRUE ~ country_name ))
This was the error I was getting, but I am not sure if the modification is changing anything that shouldn't be changed.
Error in dplyr::select(., name, continent) : trying to get slot "data" from an object (class "sf") that is not an S4 object followed by world_sp <- merge(world_sp, cor_df, by = "country_name", all.x = T, all.y = F)