library(tidyverse)
library(magrittr)
library(scales)
library(scico)
library(colorspace)
library(patchwork)
library(sf)
library(ggrepel)
library(ggstance)
library(ggdag)
library(ggraph)
library(pander)
library(countrycode)
library(here)
pound <- dollar_format(prefix = "£")
source(here("lib", "graphic-functions.R"))
# Robinson projection
projection = 54030
world_shapes <- st_read(file.path(here(), "data", "ne_110m_admin_0_countries",
"ne_110m_admin_0_countries.shp"),
quiet = TRUE) %>%
filter(ISO_A3 != "ATA")
resources <- c(
"Predictable and consistent revenue",
"Highly trained managers, staff, and volunteers",
"Carefully managed organizational structure",
"Careful board oversight",
"Geographic reach",
"Collaborative relationships with other organizations",
"Staff with local connections"
)
constraints <- c(
"Donor demands and expectations",
"Target country regime's perception of contentiousness of INGO programming",
"Legal environment and regulations in target country",
"Political trends in target country",
"Accessibility of neighboring countries"
)
tbl <- tibble(`Examples of elements of resource configurations` =
pandoc.list.return(resources, add.end.of.list = FALSE),
`Examples of institutional constraints` =
pandoc.list.return(constraints, add.end.of.list = FALSE))
pandoc.table.return(
tbl, style = "grid", keep.line.breaks = TRUE, justify = "ll",
caption = "Resource configurations and institutional constraints {#tbl:examples}"
) %T>%
cat() %>%
cat(file = here("output", "tbl-examples.md"))
Examples of elements of resource configurations | Examples of institutional constraints |
---|---|
|
|
theory_dag <- dagify(AE ~ PF,
PF ~ IC + RC,
RC ~ IC,
FIC ~ AE,
labels = c("AE" = "Advocacy\neffects",
"PF" = "Programmatic\nflexibility",
"IC" = "Institutional\nconstraints",
"RC" = "Resource\nconfiguration",
"FIC" = "Future\ninstitutional\nconstraints"),
exposure = "PF",
outcome = "AE") %>%
tidy_dagitty(layout = "mds")
theory_dag$data <- theory_dag$data %>%
mutate(linetype = ifelse(name == "AE", "dotted", "solid"))
plot_dag <- ggplot(theory_dag, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_point(size = 8) +
geom_dag_edges(start_cap = circle(4, "mm"),
end_cap = circle(4, "mm"),
aes(edge_linetype = linetype)) +
geom_dag_label_repel(aes(label = label), direction = "y", seed = 12345, size = 3) +
scale_edge_linetype_manual(values = c("dotted", "solid"), guide = FALSE) +
scale_dag() +
scale_x_continuous(expand = expand_scale(c(0.035, 0.035))) +
theme_void()
plot_dag %T>%
print() %T>%
ggsave(., filename = here("output", "theory-dag.pdf"),
width = 5, height = 2.75, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "theory-dag.png"),
width = 5, height = 2.75, units = "in", type = "cairo", dpi = 300)
# Data from the Tableau visualizations at https://monitor.civicus.org/findings/
civicus <- read_csv(here("data", "civicus_monitor_2017.csv"),
na = "Null") %>%
mutate(Population = as.double(Population), # integers can't handle world population
Rating = factor(Rating, levels = c("Open", "Narrowed", "Obstructed",
"Repressed", "Closed"),
ordered = TRUE),
iso3 = countrycode(Country, "country.name", "iso3c"))
civicus_population <- civicus %>%
group_by(Rating) %>%
summarise(pop_per_rating = sum(Population),
perc_per_rating = pop_per_rating / sum(civicus$Population)) %>%
mutate(open = Rating == "Open")
plot_civicus_population <- ggplot(civicus_population,
aes(x = perc_per_rating, y = fct_rev(Rating),
color = Rating)) +
geom_pointrangeh(aes(xmin = 0, xmax = perc_per_rating)) +
labs(x = "Percent of world population", y = NULL) +
scale_x_continuous(labels = percent_format(accuracy = 1)) +
scale_color_scico_d(palette = "roma", guide = FALSE, direction = -1) +
theme_ngo() + theme(panel.grid.major.y = element_blank())
plot_civicus_population %T>%
print() %T>%
ggsave(., filename = here("output", "civicus-population-color.pdf"),
width = 4.5, height = 2, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "civicus-population-color.png"),
width = 4.5, height = 2, units = "in", type = "cairo", dpi = 300)
(plot_civicus_population +
scale_color_scico_d(palette = "grayC", guide = FALSE, begin = 0.15)) %T>%
print() %T>%
ggsave(., filename = here("output", "civicus-population.pdf"),
width = 4.5, height = 2, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "civicus-population.png"),
width = 4.5, height = 2, units = "in", type = "cairo", dpi = 300)
map_with_civicus <- world_shapes %>%
# Fix some Natural Earth ISO weirdness
mutate(ISO_A3 = ifelse(ISO_A3 == "-99", as.character(ISO_A3_EH), as.character(ISO_A3))) %>%
mutate(ISO_A3 = case_when(
.$ISO_A3 == "GRL" ~ "DNK",
.$NAME == "Norway" ~ "NOR",
TRUE ~ ISO_A3
)) %>%
left_join(civicus, by = c("ISO_A3" = "iso3"))
plot_civicus_map <- ggplot() +
geom_sf(data = map_with_civicus, aes(fill = Rating), size = 0.15, color = "black") +
coord_sf(crs = st_crs(projection), datum = NA) +
scale_fill_scico_d(palette = "roma", na.translate = FALSE, name = "Civic space", direction = -1) +
theme_ngo_map() + theme(legend.key.size = unit(0.7, "lines"))
plot_civicus_map %T>%
print() %T>%
ggsave(., filename = here("output", "civicus-map-color.pdf"),
width = 5.5, height = 3, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "civicus-map-color.png"),
width = 5.5, height = 3, units = "in", type = "cairo", dpi = 300)