-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_bivariate_analysis.Rmd
191 lines (145 loc) · 5.37 KB
/
03_bivariate_analysis.Rmd
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
---
title: "03_bivariate_analysis"
author: "Anja Rainer"
date: "16 7 2021"
output: html_document
---
```{r setup, include=FALSE}
library(tidyverse)
library(RColorBrewer)
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, dpi = 300)
df <- tar_read(with_countries)
question_codes <- read_csv("data/processed/question_codes.csv")
```
# Merge dataframes
```{r}
# bind_cols()
# bind_rows()
```
# Bivariate analysis Gender
```{r}
# omit "this topic is not relevant" and "don't know" -> these will be turned
# to NA
answer_levels <- c("Strongly disagree", "Disagree", "Neither agree nor disagree",
"Agree", "Strongly agree")
gender_df <- df %>%
select(starts_with("A10["), E2) %>%
mutate(across(starts_with("A10["), .fns = factor, levels = answer_levels)) %>%
# remove "other" genders;
# potentially could also remove "prefer not to say", since cell counts are low
filter(E2 != "Other")
#gender_df %>%
# pivot_longer(starts_with("A10[")) %>%
# count(E2, name, value) %>%
# filter(!is.na(value)) %>%
# group_by(E2, name) %>%
# mutate(prop = n / sum(n)) %>%
# ggplot(aes(E2, prop, fill = value,)) +
# geom_col() +
# coord_flip() +
# scale_fill_manual(values = c("#FFDB6D", "#C4961A", "#F4EDCA",
"#D16103", "#C3D7A4", "#52854C", "#4E84C4", "#293352")) +
# facet_wrap(vars(name))
gender_df %>%
pivot_longer(starts_with("A10[")) %>%
count(E2, name, value) %>%
filter(!is.na(value)) %>%
group_by(E2, name) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(E2, prop, fill = value,)) +
geom_col() +
coord_flip() +
scale_fill_brewer(palette = "PuOr") +
scale_y_continuous(labels = function(x) scales::percent(x, accurarcy = 1)) +
facet_wrap(vars(name)) +
guides(fill = guide_legend(title = NULL, nrow = NULL))
```
# A1 OS practices by country
```{r, fig.width=8, fig.height=4}
# factor out function to reduce repetition
prepare_per_country <- function(df, vars, by, fac_levels) {
df %>%
select({{vars}}, {{by}}) %>%
mutate(across({{vars}}, .fns = factor, levels = fac_levels)) %>%
mutate(E1_rec = forcats::fct_lump_min({{by}}, min = 10,
other_level = "Other")) %>%
filter(E1_rec != "NA")
}
country_a1_df <- prepare_per_country(df, starts_with("A1["), E1_rec,
answer_levels)
country_a1_df %>%
pivot_longer(starts_with("A1[")) %>%
count(E1_rec, name, value) %>%
filter(!is.na(value)) %>%
group_by(E1_rec, name) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(E1_rec, prop, fill = value,)) +
geom_col() +
coord_flip() +
scale_fill_brewer(palette = "PuOr") +
facet_wrap(vars(name)) +
scale_y_continuous(labels = function(x) scales::percent(x, accurarcy = 1)) +
guides(fill = guide_legend(title = NULL, nrow = NULL)) +
labs(x = NULL, y = NULL, title = NULL)
```
# B5 hours of training by country
```{r,fig.width=8, fig.height=4}
answer_levels_b5 <- c("None", "1", "2", "3-5", "More than 5")
country_b5_df <- prepare_per_country(df, B5, E1_rec, answer_levels_b5)
country_b5_df %>%
pivot_longer(B5) %>%
count(E1_rec, name, value) %>%
filter(!is.na(value)) %>%
group_by(E1_rec, name) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(E1_rec, prop, fill = value,)) +
geom_col() +
coord_flip() +
scale_fill_brewer(palette = "PuOr") +
facet_wrap(vars(name)) +
scale_y_continuous(labels = function(x) scales::percent(x, accurarcy = 1)) +
guides(fill = guide_legend(title = NULL, nrow = NULL)) +
labs(x = NULL, y = NULL, title = NULL)
```
# B10 Preferred way to learn OS by country
```{r, fig.width=8, fig.height=4}
answer_levels_3 <- c("Yes", "No")
country_b10_df <- prepare_per_country(df, starts_with("B10["), E1_rec,
answer_levels_3)
country_b10_df %>%
pivot_longer(starts_with("B10[")) %>%
count(E1_rec, name, value) %>%
filter(!is.na(value)) %>%
group_by(E1_rec, name) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(E1_rec, prop, fill = value,)) +
geom_col() +
coord_flip() +
scale_fill_brewer(palette = "Set2") +
facet_wrap(vars(name)) +
scale_y_continuous(labels = function(x) scales::percent(x, accurarcy = 1)) +
guides(fill = guide_legend(title = NULL, nrow = NULL)) +
labs(x = NULL, y = NULL, title = NULL)
```
# C8 Degree of support in practicing OS at institution by country
```{r, fig.width=8, fig.height=4}
answer_levels_7 <- c("Don’t know/ Don’t have enough information", "I do not receive any support or incentives", "I do not receive any support or incentives but would like to", "I receive some support or incentives",
"I receive sufficient support or incentives")
country_c8_df <- prepare_per_country(df, starts_with("C8["), E1_rec,
answer_levels_7) %>%
left_join(question_codes, by = c(starts_with("C8[") = "short_code")) %>%
country_c8_df %>%
pivot_longer(starts_with("C8[")) %>%
count(E1_rec, name, value) %>%
filter(!is.na(value)) %>%
group_by(E1_rec, name) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(stringr::str_wrap(question_specification, 40), E1_rec, prop, fill = value,)) +
geom_col() +
coord_flip() +
scale_fill_brewer(palette = "PuOr") +
facet_wrap(vars(name)) +
scale_y_continuous(labels = function(x) scales::percent(x, accurarcy = 1)) +
guides(fill = guide_legend(title = NULL, nrow = NULL)) +
labs(x = NULL, y = NULL, title = NULL)
```