Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code update MSNA #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/pcs/debug-breakpoints.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"debugBreakpointsState": {
"breakpoints": [
{
"id": 0,
"path": "C:/Users/wb607344/Downloads/syria-economic-monitor/notebooks/msna/0_master.R",
"line_number": 7,
"function_steps": "",
"function_name": "toplevel",
"state": 1,
"editor_state": 1,
"editor_line_number": 7,
"is_pending_debug_completion": false,
"needs_updated_steps": false,
"type": 1,
"is_package_breakpoint": false,
"package_name": ""
}
]
}
}
9 changes: 9 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/pcs/files-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sortOrder": [
{
"columnIndex": 2,
"ascending": true
}
],
"path": "C:/Users/wb607344/Downloads/syria-economic-monitor/notebooks/msna"
}
3 changes: 3 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"activeTab": 0
}
14 changes: 14 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"left": {
"splitterpos": 258,
"topwindowstate": "NORMAL",
"panelheight": 592,
"windowheight": 630
},
"right": {
"splitterpos": 387,
"topwindowstate": "NORMAL",
"panelheight": 592,
"windowheight": 630
}
}
5 changes: 5 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"TabSet1": 0,
"TabSet2": 0,
"TabZoom": {}
}
5 changes: 5 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/rmd-outputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@





1 change: 1 addition & 0 deletions notebooks/msna/.Rproj.user/61635561/saved_source_markers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"active_set":"","sets":[]}
24 changes: 24 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/sources/per/t/3B4BA8D5
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"id": "3B4BA8D5",
"path": "C:/Users/wb607344/Downloads/syria-economic-monitor/notebooks/msna/Codes/3_2_aid.R",
"project_path": "Codes/3_2_aid.R",
"type": "r_source",
"hash": "2454355428",
"contents": "",
"dirty": false,
"created": 1700687544074.0,
"source_on_save": false,
"relative_order": 6,
"properties": {
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 1700425176,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1700425176,
"read_only": false,
"read_only_alternatives": []
}
134 changes: 134 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/sources/per/t/3B4BA8D5-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
######################################################################
# Syria Economic Monitoring
# Multi-Sectoral Needs Assesment
# 3_2_aid
######################################################################

# % HH having received aid in the 3 months -------------------------------------

aid_2022 <- msna_2022 %>%
group_by(q_k10, q_k9, q_7_1) %>%
summarise(per_aid_hh_rec = mean(q_17_1 == "Yes", na.rm = TRUE) * 100,
.groups = 'drop')

aid_2022 <- aid_2022 %>%
mutate(subdis_code = str_split(q_k9, " - ", simplify = TRUE)[, 1],
subdis_name = str_split(q_k9, " - ", simplify = TRUE)[, 2]) %>%
select(subdis_code, subdis_name, q_k10, per_aid_hh_rec, q_7_1) %>%
rename(
type_location = q_k10,
hh_pop_type = q_7_1
)

aid_2022 %>%
write_csv(
here("Data",
"Coded",
"aid_dis_2022.csv"
)
)

# Aid satisfaction -------------------------------------------------------------

aid_2022 <- msna_2022 %>%
filter(!is.na(q_17_3))

unique_q_k10 <- unique(msna_2022$q_k10)

for (value in unique_q_k10) {
subset_data <- aid_2022 %>%
filter(q_k10 == value) %>%
group_by(q_7_1, q_17_3) %>%
summarise(n = n()) %>%
mutate(percentage = round(n / sum(n) * 100, 1)) %>%
mutate(csum = rev(cumsum(rev(percentage))),
pos = percentage/2 + lead(csum, 1),
pos = if_else(is.na(pos), percentage/2, pos))

pie_chart <- ggplot(subset_data, aes(x = "", y = percentage, fill = fct_inorder(q_17_3))) +
geom_bar(stat = "identity", width = 1, color = "white") +
coord_polar(theta = "y") +
geom_label_repel(data = subset_data,
aes(y = pos, label = paste0(percentage, "%")),
size = 3, nudge_x = 0.7, show.legend = FALSE) +
labs(fill = "") +
theme_minimal() +
theme(legend.position = "right",
plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
plot.caption = element_text(hjust = 0.5, size = 10),
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank()) +
scale_fill_manual(values = pie_colors) +
facet_wrap(~q_7_1, ncol = 3)

ggsave(here("Output", paste0("pie_aid_sat_", gsub(" ", "_", value), ".png")), plot = pie_chart, width = 9, height = 6, units = "in", dpi = 300)
}

# Priority needs ---------------------------------------------------------------

needs_2022 <- msna_2022 %>%
select(id, q_7_1, q_16_1_1, q_k10) %>%
rename(need = q_16_1_1) %>%
filter(need != "All needs are met") %>%
mutate(id = id,
ones = 1,
need = ifelse(need == "Shelter assistance (emergency shelter provision, shelter repairs, rent subsidies)", "Shelter assistance", need),
need = ifelse(need %in% c("Other (specify)",
"Access to community centers and safe spaces for women and girls",
"Reintegration services", "GBV post services",
"Risk awareness and clearance (Mine Action)",
"Technical and vocational training",
"No other reasons",
"Don't know/unsure",
"Waste disposal",
"Access to safe water",
"WASH services (unloading service, toilet, handbasin, associated connections/sewage system)",
"Phone/data/communication",
"Education services",
"Electricity provision",
"Disability-specific needs (medical equipment, medicine, services)",
"Health services", "Medicine",
"Mental health and psychosocial support services (e.g. structured group activities in a safe space, invididual or group counseling, etc.)"), "Other", need),
need = ifelse(need %in% c("NFI items (e.g. clothing, blankets, cooking material, sanitation items, fuel and school equipment)", "Shelter assistance"), "Shelter assistance, NFI items", need),
need = ifelse(need %in% c("Legal advice including civil documentation and Housing, Land and Property",
"Livelihood opportunities/inability to work"), "Legal advice and documentation", need)) %>%
group_by(need, q_7_1, q_k10) %>%
summarise(total = sum(ones, na.rm = TRUE), .groups = 'drop') %>%
filter(!is.na(need)) %>%
group_by(q_7_1, q_k10) %>%
mutate(percentage = round(total / sum(total) * 100, digits = 1)) %>%
ungroup()

unique_q_k10 <- unique(safety_2022$q_k10)

for (value in unique_q_k10) {
plot_data <- filter(needs_2022, q_k10 == value)

bar_chart <- ggplot(plot_data, aes(x = percentage, y = need, fill = q_7_1)) +
geom_bar(stat = "identity", position = "dodge", width = 0.7, color = "white") +
geom_text(aes(label = percentage), position = position_dodge(width = 0.7), hjust = - 0.5, vjust = 0, size = 2) +
labs(title = "",
x = "Percentage of Households",
y = "Need") +
scale_x_continuous(limits = c(0, max(plot_data$percentage) + (max(plot_data$percentage)/10))) +
scale_fill_manual(values = bar_colors) +
theme_minimal() +
theme(
axis.text.y = element_text(size = 8),
axis.text.x = element_text(size = 10),
axis.title = element_text(size = 12, face = "bold"),
plot.title = element_text(size = 16, face = "bold"),
legend.position = "top",
legend.title = element_blank(),
legend.text = element_text(size = 10),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_line(color = "lightgray", size = 0.5),
panel.grid.minor.x = element_blank()
)

ggsave(here("Output", paste0("/bar_need", gsub("/", "_", value), ".png")), bar_chart, width = 9, height = 6)
}

# GoS-issued documentation -----------------------------------------------------
26 changes: 26 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/sources/per/t/4024B0B1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "4024B0B1",
"path": "C:/Users/wb607344/Downloads/syria-economic-monitor/notebooks/msna/0_master.R",
"project_path": "0_master.R",
"type": "r_source",
"hash": "1020133309",
"contents": "",
"dirty": false,
"created": 1700687469167.0,
"source_on_save": false,
"relative_order": 1,
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "24,13",
"scrollLine": "20"
},
"folds": "",
"lastKnownWriteTime": 1700687555,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1700687555444,
"read_only": false,
"read_only_alternatives": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
######################################################################
# Syria Economic Monitoring
# Multi-Sectoral Needs Assesment
# 0_master
######################################################################

install.packages(c("here", "tidyverse", "visdat", "summarytools", "readxl", "ggplot2", "Hmisc", "devtools"))
devtools::install_github("hadley/scales")

library(here)
library(tidyverse)
library(readxl)
library(visdat)
library(summarytools)
library(ggplot2)
library(Hmisc)
library(scales)
library(dplyr)
library(viridis)
library(ggrepel)

# Colors -----------------------------------------------------------------------

pie_colors <- c("#66c2e0", "#fae10b", "#fc8d62", "darkseagreen3", "lightpink1", "lightsteelblue1")
bar_colors <- c("#66c2e0", "#fae10b", "#fc8d62")

# Codes ------------------------------------------------------------------------

# Data cleaning
source(here("Codes", "1_cleaning.R"))

# Demographic analysis
source(here("Codes", "2_demographics.R"))

# Thematic pillars

# Conflict and household welfare
source(here("Codes", "3_1_conflict.R"))

# Humanitarian Aid
source(here("Codes", "3_2_aid.R"))

# Humanitarian Aid
source(here("Codes", "3_3_displacement.R"))

# HH welfare
source(here("Codes", "3_4_hh_welfare.R"))
24 changes: 24 additions & 0 deletions notebooks/msna/.Rproj.user/61635561/sources/per/t/6A803CB2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"id": "6A803CB2",
"path": "C:/Users/wb607344/Downloads/syria-economic-monitor/notebooks/msna/Codes/3_1_conflict.R",
"project_path": "Codes/3_1_conflict.R",
"type": "r_source",
"hash": "935954519",
"contents": "",
"dirty": false,
"created": 1700687533691.0,
"source_on_save": false,
"relative_order": 4,
"properties": {
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 1700422960,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1700422960,
"read_only": false,
"read_only_alternatives": []
}
Loading