-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudan_health_nutrition_4.R
137 lines (101 loc) · 5.91 KB
/
sudan_health_nutrition_4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#######classifying children and mothers nutrition status#######
#Adding a new underweight status column to the child data frame
child$underweight_class <- classify_underweight_child(child$waz)
#Adding a new stunting status column to the child data frame
child$stunting_status <- classify_stunting_child(child$haz)
#Adding a new stunting status column to the child data frame
child$wasting <- classify_wasting_child(child$whz, child$muac, child$oedema)
# Create a new variable to classify children based on wasting status
child_wasting <- child %>%
mutate(wasting_status = ifelse(whz < -2, 1, 0))
# Group children by state_name and calculate % wasted children per state
state_summary <- child_wasting %>%
group_by(state_name) %>%
summarise(
total_child = n(), # Count total children
wasted_child = sum(wasting_status == 1, na.rm = TRUE), # Count wasted children
percentage_undernourished = ifelse(total_child == 0, 0, (wasted_child / total_child) * 100)
)
# Create a new variable to classify mother's nutrition status based on MUAC
maternal$undernut <- classify_undernut_mother(maternal$muac)
# Create a new variable to classify undernutrition based on MUAC
maternal <- maternal %>%
mutate(nutrition_status = ifelse(muac < 220, 1, 0))
# Group mothers by state_name
state_summary <- maternal %>%
group_by(state_name) %>%
summarise(
total_mothers = n(),
undernourished_mothers = sum(nutrition_status == 1, na.rm = TRUE), # Count undernourished mothers
percentage_undernourished = ifelse(total_mothers == 0, 0, (undernourished_mothers / total_mothers) * 100)
)
#########calculating percentage malnourishment by state########
##starting by counting the values of underweight by state
child_map_underweight <- child %>% group_by(state_name,underweight_class,state_id) %>% count() %>% ungroup()
child_map_stunting <- child %>% group_by(state_name,stunting_status,state_id) %>% count() %>% ungroup()
child_map_wasting <- child %>% group_by(state_name,wasting,state_id) %>% count() %>% ungroup()
maternal_map_undernourished <- maternal %>% group_by(state_name, undernut, state_id) %>% count() %>% ungroup()
child_map_underweight <- child_map_underweight %>% group_by(state_id) %>% mutate(undernut_percentages = (get_perc(n)))
child_map_stunting <- child_map_stunting %>% group_by(state_id) %>% mutate(stunting_percentages = (get_perc(n)))
child_map_wasting <- child_map_wasting %>% group_by(state_id) %>% mutate(wasting_percentages = (get_perc(n)))
maternal_map_undernourished <- maternal_map_undernourished %>% group_by(state_id) %>% mutate(undernut_percentages = get_perc(n))
#######merging map data with the data frames###############
merged_childmap_underweight <- merge.data.frame(sudan1, child_map_underweight, by.x = "stateID", by.y = "state_id", all.x = TRUE)
merged_childmap_stunting <- merge.data.frame(sudan1, child_map_stunting, by.x = "stateID", by.y = "state_id", all.x = TRUE)
merged_childmap_wasting <- merge.data.frame(sudan1, child_map_wasting, by.x = "stateID", by.y = "state_id", all.x = TRUE)
merged_maternalmap_undernourished <- merge.data.frame(sudan1, maternal_map_undernourished, by.x = "stateID", by.y = "state_id", all.x = TRUE)
########plotting map data################
#underweight children
plot_underweight <- ggplot() +
geom_sf(data = merged_childmap_underweight, aes(geometry = geom, fill = undernut_percentages)) +
scale_fill_viridis_c(name = "Percentage of Children", option = "E", na.value = "gray50") +
labs(title = "Percentage of Underweight Children by States") +
theme_minimal()
# Add labels using geom_sf_text()
plot_underweight_with_labels <- plot_underweight +
geom_sf_text(data = merged_childmap_underweight, aes(geometry = geom, label = state_name), size = 2)
# Arrange the map using patchwork
final_map <- plot_underweight_with_labels + plot_layout(ncol = 1)
# Display the final map
final_map
#stunted children
plot_stunted <- ggplot() +
geom_sf(data = merged_childmap_stunting, aes(geometry = geom, fill = stunting_percentages)) +
scale_fill_viridis_c(name = "Percentage of Children", option = "E", na.value = "gray50") +
labs(title = "Percentage of Stunted Children by States") +
theme_minimal()
# Add labels using geom_sf_text()
plot_stunting_with_labels <- plot_stunted +
geom_sf_text(data = merged_childmap_stunting, aes(geometry = geom, label = state_name), size = 2)
# Arrange the map using patchwork
final_map <- plot_stunting_with_labels + plot_layout(ncol = 1)
# Display the final map
final_map
#Wasting children
plot_wasting <- ggplot() +
geom_sf(data = merged_childmap_wasting, aes(geometry = geom, fill = wasting_percentages)) +
scale_fill_viridis_c(name = "Percentage of Children", option = "E", na.value = "gray50") +
labs(title = "Percentage of wasted Children by States") +
theme_minimal()
# Add labels using geom_sf_text()
plot_wasting_with_labels <- plot_wasting +
geom_sf_text(data = merged_childmap_wasting, aes(geometry = geom, label = state_name), size = 2)
# Arrange the map using patchwork
final_map <- plot_wasting_with_labels + plot_layout(ncol = 1)
# Display the final map
final_map
#Undernourished mothers
plot_undernourishedmothers <- ggplot() +
geom_sf(data = merged_maternalmap_undernourished, aes(geometry = geom, fill = undernut_percentages)) +
scale_fill_viridis_c(name = "Percentage of Mothers", option = "E", na.value = "gray50") +
labs(title = "Percentage of undernourished Mothers by States") +
theme_minimal()
# Add labels using geom_sf_text()
plot_undernourishedmothers_with_labels <- plot_undernourishedmothers +
geom_sf_text(data = merged_maternalmap_undernourished, aes(geometry = geom, label = state_name), size = 2)
# Arrange the map using patchwork
final_map <- plot_undernourishedmothers_with_labels + plot_layout(ncol = 1)
# Display the final map
final_map
# Arranging the plots
plot_undernourishedmothers_with_labels + plot_wasting_with_labels + plot_stunting_with_labels + plot_underweight_with_labels