-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviolence-against-women.R
472 lines (436 loc) · 19.7 KB
/
violence-against-women.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# ------------------------------------------------------------------------------------- #
# violence-against-women #
# DATA STUDY ABOUT VIOLENCE AGAINST WOMEN IN DIFFERENT COUNTRIES #
# Author: Dennis Gluesenkamp #
# ------------------------------------------------------------------------------------- #
# ---- Libraries/packages used in this script ----
library(dplyr) # data manipulation focused on data frames
library(ggplot2) # general plotting engine
library(ggrepel) # labels with allocation line
library(showtext) # usage of Google fonts
# ---- Function to get country groups ----
getCountriesOf <- function(organization) {
if(base::tolower(organization) == 'eu'){ # European Union
org_df <- c('AT', 'BE', 'BG', 'CY', 'CZ',
'DE', 'DK', 'EE', 'ES', 'FI',
'FR', 'GB', 'GR', 'HR', 'HU',
'IE', 'IT', 'LT', 'LU', 'LV',
'MT', 'NL', 'PL', 'PT', 'RO',
'SE', 'SI', 'SK')
} else if (base::tolower(organization) == 'eu_neighborhood') { # EU neighbors
org_df <- c('AD', 'AL', 'AT', 'BA', 'BE',
'BG', 'CH', 'CY', 'CZ', 'DE',
'DK', 'EE', 'ES', 'FI', 'FR',
'GB', 'GR', 'HR', 'HU', 'IE',
'IT', 'LI', 'LT', 'LU', 'LV',
'ME', 'MK', 'MT', 'NL', 'NO',
'PL', 'PT', 'RO', 'RS', 'SE',
'SI', 'SK', 'XK')
} else if (base::tolower(organization) == 'oecd') { # OECD members
org_df <- c('AT', 'AU', 'BE', 'CA', 'CH',
'CL', 'CZ', 'DE', 'DK', 'EE',
'ES', 'FI', 'FR', 'GB', 'GR',
'HU', 'IE', 'IL', 'IS', 'IT',
'JP', 'KR', 'LT', 'LU', 'LV',
'MX', 'NL', 'NO', 'NZ', 'PL',
'PT', 'SE', 'SI', 'SK', 'TR',
'US')
}
return(org_df)
}
# ---- Style configuration ----
font_add_google(name = 'Fjalla One', family = 'Fjalla One')
font_add_google(name = 'Lora', family = 'Lora')
showtext_auto()
fontTitle = 'Fjalla One'
fontText = 'Lora'
fontSize = 20
cBackground = '#191718'
cShadow = '#59504b'
cTitle = '#c38d72'
cText = '#d9c2b6'
cScatter = c('#db5461', '#2e3b94') # first normal scatter, second highlight scatter
cHue = c('#eaddd7', '#e9beaf', '#e69e8e', '#e27b74', '#db5461', '#665E62')
cGradual = c('#f8f3f1', '#920000')
# Note: The following specifications are aligned to the later used ggsave statement which
# is optimized for a squared output.
themeViolence <- theme(
plot.background = element_rect(fill = cBackground),
panel.background = element_rect(fill = cBackground),
plot.title = element_text(size = 1.75 * fontSize,
face = 'plain',
family = fontTitle,
color = cTitle,
hjust = 0.0,
margin = unit(c(1.0, 0.0, 2.0, 0.0), 'pt')),
plot.subtitle = element_text(size = 1.25 * fontSize,
face = 'italic',
family = fontText,
color = cTitle,
hjust = 0.0,
margin = unit(c(0.0, 0.0, -1.5, 0.0), 'pt')),
plot.caption = element_text(size = 0.70 * fontSize,
face = 'plain',
family = fontText,
color = cText,
hjust = 0.0,
lineheight = 0.3,
margin = unit(c(-0.75, 0.0, -0.75, 0.0), 'pt')),
axis.title = element_text(size = 1.15 * fontSize,
face = 'bold',
family = fontText,
color = cText,
hjust = 0.5),
axis.text = element_text(size = 1.05 * fontSize,
face = 'plain',
family = fontText,
color = cText,
hjust = 0.5),
panel.border = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank(),
axis.line.x.top = element_blank(),
axis.line.x.bottom = element_blank(),
axis.line.y.left = element_blank(),
axis.line.y.right = element_blank(),
legend.position = 'right',
legend.background = element_blank(),
legend.title = element_blank(),
legend.text = element_text(size = 1.00 * fontSize,
face = 'plain',
family = fontText,
color = cTitle,
hjust = 0.0),
legend.key = element_blank(),
legend.key.size = unit(2.75, "mm"),
legend.margin = margin(0.0, 0.0, 0.0, -15.0),
complete = FALSE
)
# ---- Country ISO-code ----
iso <- ISOcodes::ISO_3166_1 %>%
dplyr::add_row(Alpha_2 = 'XK',
Alpha_3 = 'XKX',
Name = 'Kosovo') %>%
dplyr::mutate(Name = case_when(
Name == 'Czechia' ~ 'Czech Republic',
Name == 'Macedonia, Republic of' ~ 'Macedonia',
TRUE ~ Name
)) %>%
dplyr::left_join(dplyr::mutate(ggplot2::map_data('world'),
region = case_when(
region == 'UK' ~ 'United Kingdom',
TRUE ~ region
)),
by = c('Name' = 'region')) %>%
dplyr::select(Alpha_2, Alpha_3, Name, long, lat, group) %>%
dplyr::rename(code2 = Alpha_2,
code3 = Alpha_3,
country = Name,
mapgroup = group)
# ---- Attitude towards violence against women ----
# The percentage of women who agree that a husband/partner is justified in beating his
# wife/partner under certain circumstances
# Source: OECD (2019), Violence against women (indicator). doi: 10.1787/f1eb4876-en
# (Accessed on 01 October 2019)
attitudeviolence <- utils::read.csv('dat/violence.csv', sep = ',', stringsAsFactors = FALSE) %>%
dplyr::filter(REG == 'ALL' & INC == 'AIC' & VAR == 'RP_1_1') %>%
dplyr::select(LOCATION, Time, Value) %>%
dplyr::rename(code3 = LOCATION,
year = Time,
attitudeviolence = Value) %>%
dplyr::arrange(year, code3) %>%
dplyr::select(code3, year, attitudeviolence) %>%
stats::reshape(timevar = 'year', idvar = 'code3', direction = 'wide') %>%
dplyr::rename(attitudeviolence = attitudeviolence.2014)
# Note: There are several measurement times in the original data set. However, only the
# most recent survey from 2014 is used for this evaluation.
# ---- Prevalence of violence in the lifetime ----
# The percentage of women who have experienced physical and/or sexual violence from an
# intimate partner at some time in their life
# Source: OECD (2019), Violence against women (indicator). doi: 10.1787/f1eb4876-en
# (Accessed on 01 October 2019)
prevalenceviolence <- utils::read.csv('dat/violence.csv', sep = ',', stringsAsFactors = FALSE) %>%
dplyr::filter(REG == 'ALL' & INC == 'AIC' & VAR == 'RP_1_2') %>%
dplyr::select(LOCATION, Time, Value) %>%
dplyr::rename(code3 = LOCATION,
year = Time,
prevalenceviolence = Value) %>%
dplyr::arrange(year, code3) %>%
dplyr::select(code3, year, prevalenceviolence) %>%
stats::reshape(timevar = 'year', idvar = 'code3', direction = 'wide') %>%
dplyr::rename(prevalenceviolence = prevalenceviolence.2014)
# Note: There are several measurement times in the original data set. However, only the
# most recent survey from 2014 is used for this evaluation.
# ---- Creation of pooling data frame ----
df <- iso %>%
dplyr::select(code3) %>%
base::unique() %>%
dplyr::left_join(attitudeviolence, by = 'code3') %>%
dplyr::left_join(prevalenceviolence, by = 'code3')
# ---- Creation of data frame and viz for violence in the EU ----
df_euviolence <- iso %>%
dplyr::filter(code2 %in% getCountriesOf('eu')) %>%
dplyr::left_join(df, by = 'code3') %>%
dplyr::select(code2, code3, country, long, lat, mapgroup,
prevalenceviolence) %>%
dplyr::mutate(category = case_when( # Introduce categories for clearer viz
prevalenceviolence <= 0.15 ~ 'below 16%',
prevalenceviolence <= 0.20 ~ '16% to 20%',
prevalenceviolence <= 0.25 ~ '21% to 25%',
prevalenceviolence <= 0.30 ~ '26% to 30%',
prevalenceviolence > 0.30 ~ 'above 30%',
TRUE ~ 'no value'
))
# Factorize violence categories
df_euviolence$category <- factor(df_euviolence$category,
levels = c('below 16%',
'16% to 20%',
'21% to 25%',
'26% to 30%',
'above 30%',
'no value'))
# Create supporting data frame comprising EU neighbors
df_euviolence_support <- iso %>%
dplyr::filter(code2 %in% getCountriesOf('eu_neighborhood')) %>%
dplyr::filter(lat < 72)
# Drawing chart
plotViolenceEU <- ggplot() +
geom_polygon(data = df_euviolence_support,
color = cBackground,
fill = cShadow,
alpha = 0.2,
size = 0.2,
aes(x = long,
y = lat,
group = mapgroup)) +
geom_polygon(data = df_euviolence,
color = cBackground,
size = 0.5,
aes(x = long,
y = lat,
group = mapgroup,
fill = category)) +
scale_fill_manual(values = cHue) +
labs(title = 'Women experience domestic violence across the EU',
subtitle = 'Share of women suffered violence during lifetime by partners',
x = NULL,
y = NULL,
caption = 'Data source: OECD (2019), Violence against women (indicator). doi: 10.1787/f1eb4876-en\n(Accessed on 01 October 2019)',
tag = NULL) +
themeViolence +
theme( # Alternate specific elements in the standard theme
axis.text.x = element_blank(),
axis.text.y = element_blank()
)
# Export chart
ggsave(
filename = 'out/violence_eu.png',
plot = plotViolenceEU,
type = 'cairo',
width = 91.5,
height = 91.5,
units = 'mm'
)
# ---- Creation of data frame and viz for violence in OECD countries ----
df_oecdviolence <- iso %>%
dplyr::filter(code2 %in% getCountriesOf('oecd')) %>%
dplyr::left_join(df, by = 'code3') %>%
dplyr::select(code2, code3, country,
prevalenceviolence) %>%
base::unique() %>%
dplyr::mutate(category = case_when( # Introduce categories for clearer viz
prevalenceviolence <= 0.05 ~ 'below 5%',
prevalenceviolence <= 0.10 ~ '6% to 10%',
prevalenceviolence <= 0.15 ~ '11% to 15%',
prevalenceviolence <= 0.20 ~ '16% to 20%',
prevalenceviolence <= 0.25 ~ '21% to 25%',
prevalenceviolence <= 0.30 ~ '26% to 30%',
prevalenceviolence <= 0.35 ~ '31% to 35%',
prevalenceviolence <= 0.40 ~ '36% to 40%',
prevalenceviolence > 0.40 ~ 'above 40%',
TRUE ~ 'no value'
)) %>%
dplyr::filter(!is.na(prevalenceviolence))
# Reorder countries prevalence value
df_oecdviolence$code3 <- factor(df_oecdviolence$code3,
levels = df_oecdviolence$code3[base::order(-df_oecdviolence$prevalenceviolence)])
# Drawing chart
plotViolenceOECD <- ggplot() +
geom_segment(data = df_oecdviolence,
size = fontSize * 0.0125,
alpha = 0.65,
aes(x = code3,
xend = code3,
y = 0.0,
yend = prevalenceviolence,
color = prevalenceviolence)) +
geom_point(data = df_oecdviolence,
size = fontSize * 0.15,
aes(x = code3,
y = prevalenceviolence,
fill = prevalenceviolence,
color = prevalenceviolence)) +
geom_text(data = df_oecdviolence,
color = cBackground,
size = fontSize * 0.333,
aes(x = code3,
y = prevalenceviolence,
label = sprintf("%1.0f", 100*prevalenceviolence),
hjust = 0.5,
family = fontTitle)) +
geom_text(data = df_oecdviolence,
color = cText,
size = fontSize * 0.333,
aes(x = code3,
y = 0,
label = country,
angle = 90,
hjust = 0.0,
family = fontTitle)) +
scale_color_gradient(low = cGradual[1], high = cGradual[2]) +
scale_fill_gradient(low = cGradual[1], high = cGradual[2]) +
scale_y_continuous(breaks = c(0.0, 0.1, 0.2, 0.3, 0.4),
labels = c('0%', '10%', '20%', '30%', '40%'),
position = 'right') +
labs(title = 'Domestic violence is common in OECD countries',
subtitle = 'Share of women suffered violence during lifetime by partners',
x = NULL,
y = NULL,
caption = 'Data source: OECD (2019), Violence against women (indicator). doi: 10.1787/f1eb4876-en\n(Accessed on 01 October 2019); No value for Republic of Korea and Israel',
tag = NULL) +
themeViolence +
theme( # Alternate specific elements in the standard theme
axis.title = element_text(color = cTitle),
axis.text = element_text(color = cTitle),
axis.text.x = element_blank(),
panel.grid.major.y = element_line(color = cTitle,
size = 0.1,
linetype = 'dotted'),
legend.position = 'none'
)
# Export chart
ggsave(
filename = 'out/violence_oecd.png',
plot = plotViolenceOECD,
type = 'cairo',
width = 91.5,
height = 91.5,
units = 'mm'
)
# ---- Relationship between attitude towards and prevalence of violence ----
df_relation <- iso %>%
dplyr::left_join(df, by = 'code3') %>%
dplyr::select(code2, code3, country,
attitudeviolence,
prevalenceviolence) %>%
base::unique() %>%
dplyr::mutate(highlight = case_when( # Highlight specific countries
code2 %in% c('TL', 'ET', 'CD', 'JO', 'JM', 'CA', 'DE',
'CN', 'IN', 'US', 'DO', 'BO', 'JP', 'RU') ~ TRUE,
TRUE ~ FALSE
)) %>%
dplyr::mutate(country = case_when( # Abbreviate long country names
code2 == 'TL' ~ 'East Timor',
code2 == 'CD' ~ 'DR Congo',
code2 == 'BO' ~ 'Bolivia',
code2 == 'DO' ~ 'Dominican Rep.',
code2 == 'RU' ~ 'Russia',
TRUE ~ country
))
# Note: The selection for highlighted countries is purely subjective; Here, some
# major industrial nations and outliers are choosen
# Drawing chart
plotRelationPrevAtt <- ggplot() +
geom_line(data = df_relation,
stat = 'smooth',
method = 'loess',
span = 1.5,
alpha = 0.08,
color = cTitle,
aes(x = attitudeviolence,
y = prevalenceviolence)) +
geom_ribbon(data = df_relation,
stat = 'smooth',
method = 'loess',
span = 1.5,
alpha = 0.04,
fill = cText,
aes(x = attitudeviolence,
y = prevalenceviolence)) +
geom_point(data = df_relation,
alpha = 0.5,
size = 0.125 * fontSize,
aes(x = attitudeviolence,
y = prevalenceviolence,
color = highlight)) +
geom_text_repel(data = dplyr::filter(df_relation, code2 %in% c('TL', 'JM', 'US',
'DO', 'RU')),
family = fontTitle,
color = cTitle,
size = fontSize * 0.333,
hjust = 0.5,
nudge_x = 0.07,
nudge_y = 0.07,
segment.size = 0.2,
segment.color = cTitle,
aes(x = attitudeviolence,
y = prevalenceviolence,
label = country)) +
geom_text_repel(data = dplyr::filter(df_relation, code2 %in% c('BO', 'ET', 'CD',
'JO', 'DE', 'CN',
'IN', 'CA', 'JP')),
family = fontTitle,
color = cTitle,
size = fontSize * 0.333,
hjust = 0.5,
nudge_x = 0.07,
nudge_y = -0.07,
segment.size = 0.2,
segment.color = cTitle,
aes(x = attitudeviolence,
y = prevalenceviolence,
label = country)) +
scale_color_manual(values = c(cScatter[1], cScatter[2])) +
scale_size(range = c(0, 5)) +
scale_x_continuous(limits = c(0.00, 0.90),
breaks = c(0.0, 0.2, 0.4, 0.6, 0.8),
labels = c('0%', '20%', '40%', '60%', '80%')) +
scale_y_continuous(limits = c(0.00, 0.65),
breaks = c(0.0, 0.2, 0.4, 0.6, 0.8),
labels = c('0%', '20%', '40%', '60%', '80%')) +
labs(title = 'Violence prevalence vs. attitude across countries',
subtitle = 'Consent to violence and experiences of violence partly coincide',
x = 'Women agreeing violence in partnership can be justified',
y = 'Share of women suffered violence by partners',
caption = 'Data source: OECD (2019), Violence against women (indicator). doi: 10.1787/f1eb4876-en\n(Accessed on 01 October 2019); Including only those countries fully available with regard to data points',
tag = NULL) +
themeViolence +
theme( # Alternate specific elements in the standard theme
plot.title = element_text(hjust = 1.0),
plot.subtitle = element_text(hjust = 1.0,
margin = unit(c(0.0, 0.0, 1.0, 0.0), "pt")),
plot.caption = element_text(hjust = 1.0,
margin = unit(c(+4.0, 0.0, -0.75, 0.0), "pt")),
axis.title = element_text(color = cTitle),
axis.text = element_text(color = cTitle),
panel.grid.major.x = element_line(color = cTitle,
size = 0.05,
linetype = 'solid'),
panel.grid.major.y = element_line(color = cTitle,
size = 0.05,
linetype = 'solid'),
legend.position = 'none'
)
# Export chart
ggsave(
filename = 'out/relation_prevatt.png',
plot = plotRelationPrevAtt,
type = 'cairo',
width = 91.5,
height = 91.5,
units = 'mm'
)