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)
(plot_civicus_map +
scale_fill_scico_d(palette = "grayC", na.translate = FALSE,
name = "Civic space", begin = 0.15)) %T>%
print() %T>%
ggsave(., filename = here("output", "civicus-map.pdf"),
width = 5.5, height = 3, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "civicus-map.png"),
width = 5.5, height = 3, units = "in", type = "cairo", dpi = 300)
a19_budget <- read_csv(here("data", "a19_budget.csv"))
a19_budget_long <- a19_budget %>%
gather(key, value, -Year) %>%
mutate(type = ifelse(key == "Staff", "Staff", "Budget"))
plot_budget <- ggplot(filter(a19_budget_long, type == "Budget"),
aes(x = Year, y = value, color = key)) +
geom_line(size = 1) +
labs(x = NULL, y = "Reported amount") +
scale_y_continuous(labels = pound) +
scale_color_scico_d(palette = "roma", name = NULL) +
expand_limits(y = 0) +
theme_ngo()
plot_staff <- ggplot(filter(a19_budget_long, type == "Staff"),
aes(x = Year, y = value)) +
geom_line(size = 1, color = ngo_orange) +
labs(x = NULL, y = "Full time employees") +
expand_limits(y = 0) +
theme_ngo()
plot_budget_staff <- plot_budget + plot_staff +
plot_layout(ncol = 1, heights = c(1, 0.5))
plot_budget_staff %T>%
print() %T>%
ggsave(., filename = here("output", "a19-budget-staff-color.pdf"),
width = 4.5, height = 3, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-budget-staff-color.png"),
width = 4.5, height = 3, units = "in", type = "cairo", dpi = 300)
plot_budget <- plot_budget +
scale_color_scico_d(palette = "grayC", name = NULL, begin = 0.2)
plot_staff <- ggplot(filter(a19_budget_long, type == "Staff"),
aes(x = Year, y = value)) +
geom_line(size = 1, color = "grey50") +
labs(x = NULL, y = "Full time employees") +
expand_limits(y = 0) +
theme_ngo()
plot_budget_staff <- plot_budget + plot_staff +
plot_layout(ncol = 1, heights = c(1, 0.5))
plot_budget_staff %T>%
print() %T>%
ggsave(., filename = here("output", "a19-budget-staff.pdf"),
width = 4.5, height = 3, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-budget-staff.png"),
width = 4.5, height = 3, units = "in", type = "cairo", dpi = 300)
Average income per year: £2,602,296
Annual income, expenses, and surplus:
a19_budget %>%
mutate(Surplus = Income - Expenses) %>%
mutate_at(vars(Income, Expenses, Surplus), pound) %>%
pandoc.table(justify = "lllll")
Year | Income | Expenses | Staff | Surplus |
---|---|---|---|---|
2004 | £1,607,988 | £1,472,395 | 19 | £135,593 |
2005 | £1,715,683 | £1,521,699 | 22 | £193,984 |
2006 | £1,399,531 | £1,525,459 | 28 | £-125,928 |
2007 | £2,089,790 | £1,817,795 | 18 | £271,995 |
2008 | £2,086,213 | £1,780,500 | 16 | £305,713 |
2009 | £2,336,245 | £2,557,980 | 17 | £-221,735 |
2010 | £2,376,512 | £2,002,898 | 25.8 | £373,614 |
2011 | £2,155,702 | £2,111,660 | 28.2 | £44,042 |
2012 | £3,075,045 | £2,800,750 | 63 | £274,295 |
2013 | £4,028,863 | £3,649,457 | 79 | £379,406 |
2014 | £3,999,783 | £4,064,631 | 74 | £-64,848 |
2015 | £4,356,196 | £4,925,363 | 78 | £-569,167 |
a19_regional <- read_csv(here("data", "a19_regional_expenses.csv")) %>%
filter(!(Category %in% c("Governance", "Fundraising", "Law and policy"))) %>%
mutate(Category = ordered(fct_relevel(Category, "Global"))) %>%
group_by(Year, Category) %>%
summarise(Amount = sum(Amount))
plot_regions <- ggplot(a19_regional, aes(x = Year, y = Amount)) +
geom_line(size = 1, color = ngo_red) +
labs(x = NULL, y = "Reported expenditures") +
scale_y_continuous(labels = pound) +
expand_limits(y = 0) +
theme_ngo(9) +
facet_wrap(~ Category)
plot_regions %T>%
print() %T>%
ggsave(., filename = here("output", "a19-regions-expenses-abs.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-regions-expenses-abs.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)
a19_percent <- a19_regional %>%
group_by(Year) %>%
mutate(total = sum(Amount),
percent = Amount / total)
plot_percent <- ggplot(a19_percent, aes(x = Year, y = percent)) +
geom_line(size = 1, color = ngo_blue_dk) +
labs(x = NULL, y = "Percent spent on region") +
scale_y_continuous(labels = percent_format(accuracy = 1)) +
expand_limits(y = 0) +
theme_ngo(9) +
facet_wrap(~ Category)
plot_percent %T>%
print() %T>%
ggsave(., filename = here("output", "a19-regions-expenses-pct.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-regions-expenses-pct.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)
a19_offices <- read_csv(here("data", "a19_offices.csv")) %>%
# Convert lat/long to actual geometry object and convert to correct projection
st_as_sf(coords = c("long", "lat"), crs = 4326) %>%
st_transform(projection) %>%
# Extract converted lat/long for use with geom_label_repel
mutate(long = st_coordinates(.)[, 1], lat = st_coordinates(.)[, 2])
plot_a19_offices <- ggplot() +
geom_sf(data = world_shapes, size = 0.15, color = "black", fill = "grey90") +
geom_sf(data = a19_offices) +
geom_label_repel(data = a19_offices, seed = 1234,
aes(x = long, y = lat, label = office, fill = hq),
size = 3, color = "white") +
coord_sf(crs = st_crs(projection), datum = NA) +
scale_fill_scico_d(palette = "roma", guide = FALSE) +
theme_ngo_map()
plot_a19_offices %T>%
print() %T>%
ggsave(., filename = here("output", "a19-offices-color.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-offices-color.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)
(plot_a19_offices +
scale_fill_scico_d(palette = "grayC", guide = FALSE, begin = 0.5)) %T>%
print() %T>%
ggsave(., filename = here("output", "a19-offices.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-offices.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)
Middle Eastern countries where Article 19 has issued 10+ reports between 2011 and 2017, based on counts from June 19, 2017 at the Resources database.
a19_me <- read_csv(here("data", "a19_me_reports.csv")) %>%
arrange(reports) %>%
mutate(country = fct_inorder(country))
plot_me_reports <- ggplot(a19_me, aes(x = reports, y = country, color = hq)) +
geom_pointrangeh(aes(xmin = 0, xmax = reports)) +
labs(x = "Advocacy letters, reports, statements, and updates", y = NULL) +
scale_colour_manual(values = c(ngo_blue_dk, ngo_red), guide = FALSE) +
theme_ngo() + theme(panel.grid.major.y = element_blank())
plot_me_reports %T>%
print() %T>%
ggsave(., filename = here("output", "a19-me-reports.pdf"),
width = 4.5, height = 2, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "a19-me-reports.png"),
width = 4.5, height = 2, units = "in", type = "cairo", dpi = 300)
amera_budget <- read_csv(here("data", "amera_budget.csv")) %>%
mutate(cr_total = `Comic Relief` + Uganda,
cr_percent = cr_total / Income)
amera_budget_long <- amera_budget %>%
select(Year, Income, Expenses, Staff) %>%
gather(key, value, -Year) %>%
mutate(type = ifelse(key == "Staff", "Staff", "Budget"))
plot_budget_amera <- ggplot(filter(amera_budget_long, type == "Budget"),
aes(x = Year, y = value, color = key)) +
geom_line(size = 1) +
labs(x = NULL, y = "Reported amount") +
scale_y_continuous(labels = pound) +
scale_color_scico_d(palette = "roma", name = NULL) +
expand_limits(y = 0) +
theme_ngo()
plot_budget_cr <- ggplot(amera_budget, aes(x = Year, y = cr_percent)) +
geom_line(size = 1, colour = ngo_yellow) +
labs(x = NULL, y = "Percent of income\nfrom Comic Relief") +
scale_y_continuous(labels = percent_format(accuracy = 1)) +
theme_ngo()
plot_staff_amera <- ggplot(filter(amera_budget_long, type == "Staff"),
aes(x = Year, y = value)) +
geom_line(size = 1, color = ngo_orange) +
labs(x = NULL, y = "Full time\nemployees") +
expand_limits(y = 0) +
theme_ngo()
plot_budget_staff_amera <- plot_budget_amera + plot_budget_cr + plot_staff_amera +
plot_layout(ncol = 1, heights = c(1, 0.5, 0.5))
plot_budget_staff_amera %T>%
print() %T>%
ggsave(., filename = here("output", "amera-budget-staff-color.pdf"),
width = 4.5, height = 3.75, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "amera-budget-staff-color.png"),
width = 4.5, height = 3.75, units = "in", type = "cairo", dpi = 300)
plot_budget_amera <- plot_budget_amera +
scale_color_scico_d(palette = "grayC", name = NULL, begin = 0.2)
plot_budget_cr <- ggplot(amera_budget, aes(x = Year, y = cr_percent)) +
geom_line(size = 1, colour = "grey40") +
labs(x = NULL, y = "Percent of income\nfrom Comic Relief") +
scale_y_continuous(labels = percent_format(accuracy = 1)) +
theme_ngo()
plot_staff_amera <- ggplot(filter(amera_budget_long, type == "Staff"),
aes(x = Year, y = value)) +
geom_line(size = 1, color = "grey70") +
labs(x = NULL, y = "Full time\nemployees") +
expand_limits(y = 0) +
theme_ngo()
plot_budget_staff_amera <- plot_budget_amera + plot_budget_cr + plot_staff_amera +
plot_layout(ncol = 1, heights = c(1, 0.5, 0.5))
plot_budget_staff_amera %T>%
print() %T>%
ggsave(., filename = here("output", "amera-budget-staff.pdf"),
width = 4.5, height = 3.75, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "amera-budget-staff.png"),
width = 4.5, height = 3.75, units = "in", type = "cairo", dpi = 300)
Average income per year: £377,865
Annual income, expenses, and surplus:
amera_budget %>%
mutate(Surplus = Income - Expenses) %>%
mutate_at(vars(Income, Expenses, Surplus), pound) %>%
select(Year, Income, Expenses, Staff, Surplus) %>%
pandoc.table(justify = "lllll")
Year | Income | Expenses | Staff | Surplus |
---|---|---|---|---|
2004 | £112,042 | £63,531 | 21 | £48,511 |
2005 | £176,224 | £136,142 | 21 | £40,082 |
2006 | £301,223 | £286,528 | 21 | £14,695 |
2007 | £383,643 | £370,348 | 23 | £13,295 |
2008 | £638,717 | £511,949 | 21 | £126,768 |
2009 | £440,148 | £495,876 | 30 | £-55,728 |
2010 | £580,988 | £566,667 | 28 | £14,321 |
2011 | £591,992 | £464,705 | 26 | £127,287 |
2012 | £318,149 | £546,138 | 33 | £-227,989 |
2013 | £510,064 | £425,436 | 37 | £84,628 |
2014 | £369,032 | £314,520 | 1 | £54,512 |
2015 | £112,153 | £242,026 | 1 | £-129,873 |
amera_partners <- read_csv(here("data", "amera_partners.csv")) %>%
# Convert lat/long to actual geometry object and convert to correct projection
st_as_sf(coords = c("long", "lat"), crs = 4326) %>%
st_transform(projection) %>%
# Extract converted lat/long for use with geom_label_repel
mutate(long = st_coordinates(.)[, 1], lat = st_coordinates(.)[, 2])
plot_amera_offices <- ggplot() +
geom_sf(data = world_shapes, size = 0.15, color = "black", fill = "grey90") +
geom_sf(data = amera_partners) +
geom_label_repel(data = amera_partners, seed = 1234,
aes(x = long, y = lat, label = office, fill = hq),
size = 3, color = "white") +
coord_sf(crs = st_crs(projection), datum = NA) +
scale_fill_scico_d(palette = "roma", guide = FALSE) +
theme_ngo_map()
plot_amera_offices %T>%
print() %T>%
ggsave(., filename = here("output", "amera-partners-color.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "amera-partners-color.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)
(plot_amera_offices +
scale_fill_scico_d(palette = "grayC", guide = FALSE, begin = 0.5)) %T>%
print() %T>%
ggsave(., filename = here("output", "amera-partners.pdf"),
width = 5.5, height = 2.5, units = "in", device = cairo_pdf) %>%
ggsave(., filename = here("output", "amera-partners.png"),
width = 5.5, height = 2.5, units = "in", type = "cairo", dpi = 300)