Skip to content

Commit

Permalink
Fixed separation of countries with level 1 and level 2 data
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardMN committed Jun 21, 2021
1 parent 628a22f commit 5a11397
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions inst/make_hexsticker.R
Expand Up @@ -19,30 +19,35 @@ regional_countries <- get_available_datasets() %>%
regional_countries_l2 <- regional_countries %>%
filter(!(is.na(.data$level_2_region)))

regional_countries_l1 <- regional_countries %>%
filter(is.na(.data$level_2_region))

# get world data
world <- ms_simplify(spData::world %>%
st_as_sf(), keep = 0.04)
world <- spData::world %>%
st_as_sf()

regional_maps <- ms_simplify(ne_states(gsub(' \\(.*\\)', "", regional_countries$origin,perl=TRUE),
returnclass = "sf"), keep = 0.04) %>%
mutate(
region_code = paste("Level", woe_id %% 7 + 3)
)
# regional_maps <- ms_simplify(ne_states(gsub(' \\(.*\\)', "", regional_countries$origin,perl=TRUE),
# returnclass = "sf"), keep = 0.04) %>%
# mutate(
# region_code = paste("Level", woe_id %% 7 + 3)
# )


world_without_regions <- ne_countries(returnclass = "sf") %>%
filter(sovereignt != "Antarctica")

regional_maps <- ms_simplify(ne_states(gsub(' \\(.*\\)', "", regional_countries$origin,perl=TRUE),
returnclass = "sf"), keep = 0.04) %>%
mutate(
#region_code = paste("Level", woe_id %% 7 + 3)
region_code = woe_id %% 7 +
if_else(admin %in%
countryname(regional_countries_l2[["origin"]], destination = "country.name.en"),
0, 7)
)
numberOfLevels <- 4
regional_maps_l1 <- ms_simplify(
ne_states(gsub(' \\(.*\\)', "",
regional_countries_l1$origin, perl=TRUE),returnclass = "sf") %>%
mutate( region_code = woe_id %% numberOfLevels), keep = 0.04)

regional_maps_l2 <- ms_simplify(
ne_states(gsub(' \\(.*\\)', "",
regional_countries_l2$origin, perl=TRUE),returnclass = "sf") %>%
mutate( region_code = woe_id %% numberOfLevels + numberOfLevels + 1), keep = 0.04)

regional_maps <- bind_rows(regional_maps_l1, regional_maps_l2)

# mark supported countries from the world data
supported_countries <- world %>%
Expand Down
Binary file modified man/figures/logo5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a11397

Please sign in to comment.