-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRiskDefSummaryEOP.Rmd
133 lines (100 loc) · 3.5 KB
/
RiskDefSummaryEOP.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
---
title: "Risk Definition Summary"
date: "`r Sys.Date()`"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
message = FALSE,
warning = FALSE)
library(googledrive)
library(pacman)
p_load(magrittr, gsubfn, stringr, tidyverse)
```
## Full questionaire results
### Open from DATE 2023 to DATE 2023
[This is the survey form.](https://docs.google.com/forms/d/1GBkgRn6prtdQmsBfJ_NDcbK7dOx_A4TyMcy2eXs9qcI/edit)
```{r getsurvey}
#survey link
#results https://docs.google.com/spreadsheets/d/1ZAsKj3Yw78DTn6F22QY0hBZnnb19Sopt8F_3OYTh010/edit#gid=1300898964
# this code gets from google drive, need to enter oauth token so probably not bulletproof for all users
# resultfile <- drive_get("https://docs.google.com/spreadsheets/d/1ZAsKj3Yw78DTn6F22QY0hBZnnb19Sopt8F_3OYTh010/edit#gid=1300898964")
# responses <- drive_download(resultfile, type = "csv", overwrite = TRUE) %>%
# {read.csv(.$local_path)}
# once file has been downloaded use this
responses <- read.csv("EAFM Risk Assessment Review (Responses).csv",header=T)
# separate question number and element name? numbers are duplicates so just use name
names(responses) <- sub("^X.*\\.\\.\\.","",names(responses))
# take only the elements
elements <- responses[,4:46]
currentelements <- elements[,1:24]
newelements <- elements[,25:43]
```
We had `r nrow(responses)` responses.
### Summary of responses by Element
Ordered by most frequent answer
#### Current Risk Elements
```{r plotcurrent, fig.height=10, fig.width=7.5}
# barplot for each column of a dataframe from https://stackoverflow.com/questions/52822840/ggplot2-create-a-barplot-for-every-column-of-a-dataframe
# desired workflow:
# make each column just the first portion, original or alternate
# count each category
# summarize in a bar or pie plot
# currently having difficulty with list structure and purrr
# one column
# element <- names(elements)[1]
#
# test <- elements[1] |>
# map_df(str_squish) |> # removes whitespace
# #separate(Stock.Assessment.Performance,
# # into = c("version", "description"), sep = ":")
# ggplot(aes(x = .data[[element]])) +
# geom_bar() +
# theme_bw() +
# scale_x_discrete(labels = function(x) str_wrap(x, width = 20)) +
# labs(title = element)
plotdef <- function(elements){
for(i in 1:length(names(elements))){
n <- names(elements)[i]
barpl <- elements[i] |>
map_df(str_squish) |> # removes whitespace
filter(.data[[n]]!= "") |>
ggplot(aes(x = reorder(.data[[n]],.data[[n]], function(x)-length(x)))) +
geom_bar() +
theme_bw() +
scale_x_discrete(labels = function(x) str_wrap(x, width = 20)) +
xlab(NULL) +
labs(title = n)
cat("\n")
print(barpl)
cat("\n")
}
}
plotdef(currentelements)
```
#### Potentially New Risk Elements
```{r plotnew, fig.height=10, fig.width=7.5}
plotdef(newelements)
```
```{r plotflip, fig.height=10, fig.width=7.5}
plotdefflip <- function(elements){
for(i in 1:length(names(elements))){
n <- names(elements)[i]
barpl <- elements[i] |>
map_df(str_squish) |> # removes whitespace
filter(.data[[n]]!= "") |>
ggplot(aes(x = reorder(.data[[n]],.data[[n]], function(x)+length(x)))) +
geom_bar() +
theme_bw() +
scale_x_discrete(labels = function(x) str_wrap(x, width = 60)) +
xlab(NULL) +
coord_flip() +
labs(title = n)
cat("\n")
print(barpl)
cat("\n")
}
}
longnewelements <- elements[,41:42]
plotdefflip(longnewelements)
```