Loading Data
mwl_r9 <- "https://www.afrobarometer.org/wp-content/uploads/2023/06/afrobarometer_release-dataset_mlw_r9_en_2023-03-01.sav" %>%
url() %>%
read_sav()
## codebook
codebook <- mwl_r9 %>%
get_label() %>%
enframe() %>%
rename(
variable = name,
label = value
)
codebook # view variables
## # A tibble: 382 × 2
## variable label
## <chr> <chr>
## 1 RESPNO Respondent number
## 2 URBRUR Urban or Rural Primary Sampling Unit
## 3 REGION Province or region
## 4 EA_SVC_A EA-SVC-A. Electricity grid in the PSU/EA
## 5 EA_SVC_B EA-SVC-B. Piped water system in the PSU/EA
## 6 EA_SVC_C EA-SVC-C. Sewage system in the PSU/EA
## 7 EA_SVC_D EA-SVC-D. Mobile phone service in the PSU/EA
## 8 EA_SVC_E EA-SVC-E. Borehole or tubewell in PSU/EA
## 9 EA_FAC_A EA-FAC-A. Post office in the PSU/EA
## 10 EA_FAC_B EA-FAC-B. School in the PSU/EA
## # ℹ 372 more rows
General Perception
mwl_r9 %<>%
mutate(
Q38F = case_match(Q38F,
0 ~ "None",
1 ~ "Some of them",
2 ~ "Most of them",
3 ~ "All of them",
8 ~ "Refused to answer",
9 ~ "Don't know"
),
REGION = case_match(REGION,
460 ~ "North",
461 ~ "Center",
462 ~ "South" ),
URBRUR = case_match(URBRUR,
1 ~ "Urban",
2 ~ "Rural",
3 ~ "Peri-Urban")
)
## corruption percetion
p1 <- mwl_r9 %>%
count(Q38F, sort = T) %>%
mutate(
perc = round(n/sum(n)*100)) %>%
ggplot(
aes(perc, fct_reorder( Q38F, perc)
), fill = "lightgrey"
) +
geom_col(show.legend = F, width = .7) +
theme_minimal() +
labs(
y = NULL,
title = "Corruption perception",
subtitle = "How many of the following people do you think are involved in corruption, or haven’t \n you heard enough about them to say? Judges and magistrates",
x = "%",
caption = "Source: Afrobarometer 2022"
) +
theme(
axis.ticks = element_blank(),
plot.subtitle = element_text(
face = "italic"
),
plot.title = element_textbox_simple(
face = "bold"
)
)
p1 +
geom_text(
aes(label = perc %>%
str_c("%"), hjust =0)
) +
xlim(c(0, 55))

By Region
mwl_r9 %>%
count(REGION, sort = T) %>%
mutate(
percent = round(n/sum(n)*100)
) #sample distribution by region
## # A tibble: 3 × 3
## REGION n percent
## <chr> <int> <dbl>
## 1 Center 528 44
## 2 South 520 43
## 3 North 152 13
mwl_r9 %>%
ggplot(aes(
REGION, fill = Q38F
)) +
geom_bar(position = "dodge") +
scale_fill_brewer(
palette = "Set2"
) +
labs(
fill = "Response",
x = NULL
) +
theme_minimal() +
labs(
y = "count",
title = "Corruption perception",
subtitle = "How many of the following people do you think are involved in corruption, or haven’t \n you heard enough about them to say? Judges and magistrates",
caption = "Source: Afrobarometer 2022"
) +
theme(
plot.title = element_text(
face = "bold"
),
plot.subtitle = element_text(
face = "italic"
)
)

### percent
mwl_r9 %>%
group_by(REGION, Q38F) %>%
tally() %>%
mutate(perc = round(n/sum(n)*100))%>%
ggplot(
aes(perc, REGION,fill = Q38F)
) +
geom_col( width = .5) +
labs(
fill = "Response",
x = "%",
y = NULL,
title = "Corruption perception",
subtitle = "How many of the following people do you think are involved in corruption, or \n haven’t you heard enough about them to say? Judges and magistrates",
x = "%",
caption = "Source: Afrobarometer 2022"
) +
scale_fill_brewer(
palette = "Set3"
) +
theme_minimal() +
theme(
plot.title = element_text(
face = "bold"
),
plot.subtitle = element_text(
face = "italic"
)
)+
geom_text(position = position_stack(vjust = .5),
aes(label = perc %>%
str_c("%"))
)

Rural vs. Urban
mwl_r9 %>%
group_by(URBRUR, Q38F) %>%
tally() %>%
mutate(
perc = round(n/sum(n)*100)
) %>%
filter(!Q38F == "Refused to answer") %>%
ggplot(
aes(
perc, factor(URBRUR, c("Rural","Urban", "Peri-Urban")), fill = Q38F
)
) +
geom_col(width = .6)+
labs(
fill = "Response",
y = NULL,
x =NULL,
title = "Corruption perception",
subtitle = "How many of the following people do you think are involved in corruption, or \n haven’t you heard enough about them to say? Judges and magistrates",
x = "%",
caption = "Source: Afrobarometer 2022"
) +
theme_fivethirtyeight()+
theme(
panel.grid.minor = element_blank(),
plot.subtitle = element_text(
face = "italic"
)
) +
scale_fill_brewer(
palette = "Set3"
)+
geom_text(position = position_stack(vjust = .5),
aes(label = perc %>%
str_c("%"))
)

By Party Identification
## party Q89B
mwl_r9 %<>%
mutate(
Q89B = case_match(Q89B,
460 ~ "AFORD",
461 ~ "DPP",
462 ~ "MAFUNDE",
463 ~ "MCP",
464 ~ "NSF",
465 ~ "NARC",
466 ~ "PDM",
467 ~ "PP",
468 ~"PPM",
469 ~"PETRA",
470 ~"RP",
471 ~"UDF",
472 ~"NLP",
473 ~ "CCP",
474 ~"UIP",
475 ~"UTM",
476 ~"MMD",
9995 ~"?",
9997 ~ "Not Applicable",
9998 ~ "Refused to answer",
9999 ~"Don't know"
),
Q89A = case_match(Q89A,
0 ~"No (does NOT feel close to ANY party)",
1 ~ "Yes (feels close to a party)",
8 ~"Refused to answer",
9 ~" Don’t know"
)
)
## close to any part
freq(mwl_r9$Q89A,report.nas = F, order = "freq")
## Frequencies
## mwl_r9$Q89A
## Type: Character
##
## Freq % % Cum.
## ------------------------------------------- ------ -------- --------
## Yes (feels close to a party) 734 61.17 61.17
## No (does NOT feel close to ANY party) 443 36.92 98.08
## Refused to answer 20 1.67 99.75
## ·Don’t know 3 0.25 100.00
## Total 1200 100.00 100.00
## party identification
freq(mwl_r9$Q89B,report.nas = F, order = "freq")
## Frequencies
## mwl_r9$Q89B
## Type: Character
##
## Freq % % Cum.
## ----------------------- ------ --------- ---------
## Not Applicable 466 38.833 38.833
## DPP 366 30.500 69.333
## MCP 247 20.583 89.917
## UTM 66 5.500 95.417
## UDF 42 3.500 98.917
## Refused to answer 7 0.583 99.500
## PP 3 0.250 99.750
## ? 2 0.167 99.917
## MMD 1 0.083 100.000
## Total 1200 100.000 100.000
mwl_r9 %>%
filter(Q89B %in% c("DPP", "MCP", "UDF", "UTM")) %>% # relevant parties
group_by(Q89B,Q38F) %>%
tally() %>%
mutate(perc = round(n/sum(n)*100)) %>%
ggplot(
aes(perc, Q89B, fill = Q38F)
) +
geom_col(width = .6)+
theme_fivethirtyeight()+
theme(
panel.grid.minor = element_blank(),
plot.subtitle = element_text(
face = "italic"
)
) +
scale_fill_brewer(
palette = "Set3"
) +
labs(
fill = "Response",
y = NULL,
x =NULL,
title = "Corruption perception",
subtitle = "How many of the following people do you think are involved in corruption, or \n haven’t you heard enough about them to say? Judges and magistrates",
x = "%",
caption = "Source: Afrobarometer 2022"
) +
geom_text(position = position_stack(vjust = .5),
aes(label = perc %>%
str_c("%"))
)
