-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript_Survey.R
342 lines (274 loc) · 15.3 KB
/
Script_Survey.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
#####################################################
############ Vragenlijst ###########################
#####################################################
library(readxl)
library(ggplot2)
library(tidyverse)
library(forcats)
# Read data
data <- read_excel("data/Vragenlijst Rattenmonitor INBO_Complete.xlsx", sheet = 1)
#View(data)
##Plots
colnames(data)
# which municipalities
data$Gemeente
#1 melding openbaar domein --> actie ja/nee
# Summarize data: count occurrences of each value in the column
data_summary <- data %>%
group_by(`Wanneer een inwoner melding maakt van ratten op openbaar domein, wordt er dan een actie ondernomen (bestrijding, uitdelen van rodenticiden, preventieve maatregelen, informatie verstrekken)?`) %>%
summarize(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
# Clean up the data
colnames(data_summary)[1] <- "answer"
data_summary <- data_summary %>%
mutate(answer = ifelse(answer %in% c("Nee",
"Ja, door personeel van de gemeente",
"Ja, door een externe firma in opdracht van de gemeente",
"We krijgen zulke meldingen niet"), answer, "Ander"))
data_summary$percentage[which(data_summary$answer=="Ander")]<-sum(data_summary$percentage[which(data_summary$answer=="Ander")])
data_summary <- data_summary %>%
group_by(answer) %>%
filter(answer != "Ander" | row_number() == 1) %>%
ungroup()
data_summary$answer <- factor(data_summary$answer,
levels = c("Ja, door een externe firma in opdracht van de gemeente",
"Ja, door personeel van de gemeente",
"Nee",
"We krijgen zulke meldingen niet",
"Ander"))
# Reorder levels
data_summary$answer <- fct_relevel(data_summary$answer,"Ja, door een externe firma in opdracht van de gemeente",
"Ja, door personeel van de gemeente",
"Nee",
"We krijgen zulke meldingen niet",
"Ander")
# Create the pie chart
ggplot(data_summary, aes(x = "", y = percentage, fill = answer)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background, axes, and grid
guides(fill = guide_legend(title = NULL))+
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5)) +
theme(legend.text = element_text(size = 12))
# Reverse the factor levels for fill (colors) without altering the actual data order
data_summary$answer_fill <- fct_rev(data_summary$answer)
# Create the stacked horizontal bar chart with consistent stacking and reversed colors
plot_melding_openbaar<-ggplot(data_summary, aes(x = 1, y = percentage, fill = answer_fill)) +
geom_bar(stat = "identity", width = 0.5) + # Adjust bar width
coord_flip() + # Flip the coordinates for a horizontal bar chart
scale_x_continuous(limits = c(0, 2)) + # Set Y-axis range (now X-axis due to flip)
theme_minimal() + # Use a clean minimal theme
labs(x = NULL, y = NULL, fill = NULL) + # Remove axis labels and legend title
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5), size = 4) + # Ensure labels are positioned correctly
guides(fill = guide_legend(reverse = TRUE)) + # Reverse the legend order
theme(legend.position = "none", # Move legend to the bottom
axis.text = element_blank(), # Remove axis text
axis.ticks = element_blank(),
panel.grid = element_blank(), # Remove all gridlines
panel.grid.major = element_blank(), # Remove major gridlines (optional)
panel.grid.minor = element_blank() # Remove minor gridlines (optional)
) # Remove axis ticks
#1 melding privaat terrein --> actie ja/nee
# Summarize data: count occurrences of each value in the column
data_summary <- data %>%
group_by(`Wanneer een inwoner melding maakt van ratten op privaat terrein, wordt er dan een actie ondernomen (bestrijding, uitdelen van rodenticiden, preventieve maatregelen, informatie verstrekken)?`) %>%
summarize(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
# Clean up the data
colnames(data_summary)[1] <- "answer"
data_summary <- data_summary %>%
mutate(answer = ifelse(answer %in% c("Nee",
"Ja, door personeel van de gemeente",
"Ja, door een externe firma in opdracht van de gemeente",
"We krijgen zulke meldingen niet"), answer, "Ander"))
data_summary$percentage[which(data_summary$answer=="Ander")]<-sum(data_summary$percentage[which(data_summary$answer=="Ander")])
data_summary <- data_summary %>%
group_by(answer) %>%
filter(answer != "Ander" | row_number() == 1) %>%
ungroup()
data_summary$answer <- factor(data_summary$answer,
levels = c("Ja, door een externe firma in opdracht van de gemeente",
"Ja, door personeel van de gemeente",
"Nee",
"We krijgen zulke meldingen niet",
"Ander"))
# Reorder levels
data_summary$answer <- fct_relevel(data_summary$answer,"Ja, door een externe firma in opdracht van de gemeente",
"Ja, door personeel van de gemeente",
"Nee",
"We krijgen zulke meldingen niet",
"Ander")
# Create the pie chart
ggplot(data_summary, aes(x = "", y = percentage, fill = answer)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background, axes, and grid
guides(fill = guide_legend(title = NULL))+
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5)) +
theme(legend.text = element_text(size = 12))
# Reverse the factor levels for fill (colors) without altering the actual data order
data_summary$answer_fill <- fct_rev(data_summary$answer)
# Create the stacked horizontal bar chart with consistent stacking and reversed colors
plot_melding_privaat<-ggplot(data_summary, aes(x = 1, y = percentage, fill = answer_fill)) +
geom_bar(stat = "identity", width = 0.5) + # Adjust bar width
coord_flip() + # Flip the coordinates for a horizontal bar chart
scale_x_continuous(limits = c(0, 2)) + # Set Y-axis range (now X-axis due to flip)
theme_minimal() + # Use a clean minimal theme
labs(x = NULL, y = NULL, fill = NULL) + # Remove axis labels and legend title
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5), size = 4) + # Ensure labels are positioned correctly
guides(fill = guide_legend(reverse = TRUE)) + # Reverse the legend order
theme(legend.position = "bottom",# Move legend to the bottom
legend.text = element_text(size = 12),
axis.text = element_blank(), # Remove axis text
axis.ticks = element_blank(),
panel.grid = element_blank(), # Remove all gridlines
panel.grid.major = element_blank(), # Remove major gridlines (optional)
panel.grid.minor = element_blank() # Remove minor gridlines (optional)
) # Remove axis ticks
# Combine both plots
plot_melding_openbaar
plot_melding_privaat
library(patchwork)
combined<-plot_melding_openbaar/plot_melding_privaat
#2
# Summarize data: count occurrences of each value in the column
data_summary <- data %>%
filter(`Hoe worden deze gegevens bijgehouden binnen de gemeente?...19` != "NA") %>% # Drop rows where the answer is "NA"
group_by(`Hoe worden deze gegevens bijgehouden binnen de gemeente?...19`) %>%
summarize(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
# Clean up the data
colnames(data_summary)[1] <- "answer"
data_summary <- data_summary %>%
mutate(answer = ifelse(answer %in% c("In een digitaal registratiesysteem waar enkel de melding wordt bijgehouden, zonder eventuele acties die hieraan gekoppeld zijn",
"In een digitaal registratiesysteem waar zowel de melding als de actie die hieraan gekoppeld zijn worden bijgehouden", "Op papier, waar enkel de melding wordt bijgehouden, zonder eventuele acties die hieraan gekoppeld zijn", "Op papier, waar zowel de melding als de hieraan gekoppelde acties worden bijgehouden",
"Deze worden niet geregistreerd"), answer, "Ander"))
data_summary$percentage[which(data_summary$answer=="Ander")]<-sum(data_summary$percentage[which(data_summary$answer=="Ander")])
data_summary <- data_summary %>%
group_by(answer) %>%
filter(answer != "Ander" | row_number() == 1) %>%
ungroup()
# Create the pie chart
ggplot(data_summary, aes(x = "", y = percentage, fill = answer)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background, axes, and grid
guides(fill = guide_legend(title = NULL))+
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5)) +
theme(legend.text = element_text(size = 8.5))
#3
# Summarize data: count occurrences of each value in the column
data_summary <- data %>%
filter(`Zou u bereid zijn om deze gegevens door te geven aan INBO voor de rattenmonitortool?` != "NA") %>% # Drop rows where the answer is "NA"
group_by(`Zou u bereid zijn om deze gegevens door te geven aan INBO voor de rattenmonitortool?`) %>%
summarize(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
# Clean up the data
colnames(data_summary)[1] <- "answer"
#View(data_summary)
data_summary <- data_summary %>%
mutate(answer = ifelse(answer %in% c("Ja","Nee"), answer, "Ander"))
data_summary$percentage[which(data_summary$answer=="Ander")]<-sum(data_summary$percentage[which(data_summary$answer=="Ander")])
data_summary <- data_summary %>%
group_by(answer) %>%
filter(answer != "Ander" | row_number() == 1) %>%
ungroup()
# Create the pie chart
ggplot(data_summary, aes(x = "", y = percentage, fill = answer)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background, axes, and grid
guides(fill = guide_legend(title = NULL))+
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5)) +
theme(legend.text = element_text(size = 12))
data_summary$answer <- factor(data_summary$answer,
levels = c("Ja",
"Nee",
"Ander"))
# Reorder levels
data_summary$answer <- fct_relevel(data_summary$answer,"Ja",
"Nee",
"Ander")
# Reverse the factor levels for fill (colors) without altering the actual data order
data_summary$answer_fill <- fct_rev(data_summary$answer)
# Create the stacked horizontal bar chart with consistent stacking and reversed colors
plot_datadelen<-ggplot(data_summary, aes(x = 1, y = percentage, fill = answer_fill)) +
geom_bar(stat = "identity", width = 0.5) + # Adjust bar width
coord_flip() + # Flip the coordinates for a horizontal bar chart
scale_x_continuous(limits = c(0, 2)) + # Set Y-axis range (now X-axis due to flip)
theme_minimal() + # Use a clean minimal theme
labs(x = NULL, y = NULL, fill = NULL) + # Remove axis labels and legend title
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5), size = 4) + # Ensure labels are positioned correctly
guides(fill = guide_legend(reverse = TRUE)) + # Reverse the legend order
theme(legend.position = "none", # Move legend to the bottom
axis.text = element_blank(), # Remove axis text
axis.ticks = element_blank(),
panel.grid = element_blank(), # Remove all gridlines
panel.grid.major = element_blank(), # Remove major gridlines (optional)
panel.grid.minor = element_blank() # Remove minor gridlines (optional)
) # Remove axis ticks
# Summarize data: count occurrences of each value in the column
data_summary <- data %>%
filter(`Zou u bereid zijn om deze gegevens openbaar te delen via internationale platformen zoals GBIF?` != "NA") %>% # Drop rows where the answer is "NA"
group_by(`Zou u bereid zijn om deze gegevens openbaar te delen via internationale platformen zoals GBIF?`) %>%
summarize(count = n()) %>%
mutate(percentage = count / sum(count) * 100)
# Clean up the data
colnames(data_summary)[1] <- "answer"
#View(data_summary)
data_summary <- data_summary %>%
mutate(answer = ifelse(answer %in% c("Ja","Nee"), answer, "Ander"))
data_summary$percentage[which(data_summary$answer=="Ander")]<-sum(data_summary$percentage[which(data_summary$answer=="Ander")])
data_summary <- data_summary %>%
group_by(answer) %>%
filter(answer != "Ander" | row_number() == 1) %>%
ungroup()
# Create the pie chart
ggplot(data_summary, aes(x = "", y = percentage, fill = answer)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void() + # Remove background, axes, and grid
guides(fill = guide_legend(title = NULL))+
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5)) +
theme(legend.text = element_text(size = 12))
data_summary$answer <- factor(data_summary$answer,
levels = c("Ja",
"Nee",
"Ander"))
# Reorder levels
data_summary$answer <- fct_relevel(data_summary$answer,"Ja",
"Nee",
"Ander")
# Reverse the factor levels for fill (colors) without altering the actual data order
data_summary$answer_fill <- fct_rev(data_summary$answer)
# Create the stacked horizontal bar chart with consistent stacking and reversed colors
plot_GBIF<-ggplot(data_summary, aes(x = 1, y = percentage, fill = answer_fill)) +
geom_bar(stat = "identity", width = 0.5) + # Adjust bar width
coord_flip() + # Flip the coordinates for a horizontal bar chart
scale_x_continuous(limits = c(0, 2)) + # Set Y-axis range (now X-axis due to flip)
theme_minimal() + # Use a clean minimal theme
labs(x = NULL, y = NULL, fill = NULL) + # Remove axis labels and legend title
geom_text(aes(label = paste0(round(percentage, 1), "%")),
position = position_stack(vjust = 0.5), size = 4) + # Ensure labels are positioned correctly
guides(fill = guide_legend(reverse = TRUE)) + # Reverse the legend order
theme(legend.position = "bottom", # Move legend to the bottom
legend.text = element_text(size=12),
axis.text = element_blank(), # Remove axis text
axis.ticks = element_blank(),
panel.grid = element_blank(), # Remove all gridlines
panel.grid.major = element_blank(), # Remove major gridlines (optional)
panel.grid.minor = element_blank() # Remove minor gridlines (optional)
) # Remove axis ticks
# Combine both plots
plot_datadelen
plot_GBIF
combined<-plot_datadelen/plot_GBIF
combined