Skip to content

Commit

Permalink
Initial work to show regions for countries where we have regional data
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardMN committed Jun 20, 2021
1 parent 06a7eb4 commit a137ddf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions inst/make_hexsticker.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
library(covidregionaldata)
library(hexSticker)
library(showtext)
library(ggplot2)
library(dplyr)
library(maps)
library(countrycode)
library(sf)
library(rnaturalearth)
library(rmapshaper)

# font setup
font_add_google("Zilla Slab Highlight", "useme")

# get countries we have data for
regional_countries <- get_available_datasets() %>%
filter(type == "regional")
filter(.data$type == "regional")

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

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

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)
)


# mark supported countries from the world data
supported_countries <- world %>%
Expand Down Expand Up @@ -86,6 +97,36 @@ covid_map_2 <- ggplot() +

print(covid_map_2)

covid_map_3 <- ggplot() +
ggspatial::layer_spatial(data = supported_countries, aes(fill = fill, size = fill, color = fill)) +
coord_sf(crs = "ESRI:54016") +
scale_fill_manual(
name = "",
values = c("#0072b2", "#cc79a7", "grey80",
"#0072b2", "#cc79a7", "grey80",
"#0072b2", "#cc79a7", "grey80",
"#0072b2", "#cc79a7", "grey80",
"#0072b2", "#cc79a7", "grey80")
) +
scale_color_manual(
name = "",
values = c("black", "black", "#666666")
) +
scale_size_manual(
name = "",
values = c(0.1, 0.1, 0.018)
) +
ggplot() +
ggspatial::layer_spatial(data = regional_maps,
aes(fill = fill,
size = 0.002)) +
coord_sf(crs = "ESRI:54016") +
# scale_fill_brewer(palette = "Blues") +
theme_void() +
theme(legend.position = "none", axis.text.x = element_blank())

print(covid_map_3)

logo2 <- sticker(
covid_map_2,
package = "covidregionaldata",
Expand Down Expand Up @@ -113,3 +154,4 @@ logo3 <- sticker(
u_size = 3.5,
dpi = 1000
)

Binary file modified man/figures/logo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/logo3.png
Loading
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 a137ddf

Please sign in to comment.