---
title: "ESMAC survey"
author: "Morgan Sangeux, Stéphane Armand, and Brian Horsak for ESMAC"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  html_document: 
    toc: true
    toc_float: true
    toc_depth: 3
    number_sections: true
    theme: united
    highlight: tango
  pdf_document:
    fig_caption: true
    number_sections: true
    highlight: tango 
---

`\newpage \tableofcontents \newpage`{=latex}

# Introduction

This document summarises the results of the survey which was conducted by ESMAC. The html page was generated with R markdown from one Excel document.

```{r setup, include=FALSE}
#### Install / load package ####
rm(list = ls())
usePackage <- function(p) 
{
  if (!is.element(p, installed.packages()[,1]))
    install.packages(p, dep = TRUE)
  require(p, character.only = TRUE)
}

usePackage("openxlsx")
usePackage("tidyverse")
usePackage("ggpubr")
usePackage("knitr")
usePackage("RColorBrewer")
usePackage("stringr")

#### Specify location of data file (Excel document) and loading of data
datafile = "..\\Data\\Data.xlsx"
SurveyData <- read.xlsx(xlsxFile = datafile, sheet = "Data4Processing", skipEmptyRows = FALSE)

### Loading of additional label for the questions (same Excel file)
LabelData <- read.xlsx(xlsxFile = datafile, sheet = "Questions_Code", skipEmptyRows = FALSE)
LabelData <- LabelData %>% separate(Num,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0")) 

#### Sub functions
## Create or not a table of other comments
doTable <- function(data,col.names){
  ""
  # The following line may be commented on/off to disable/enable the table outputs
  #kable(data,col.names=col.names)
}
## Three functions to dynamically modify the content of some columns depending on use case
OtherModifyCol <- function(ICol,OCol,replacement,colname = 'Out')
{
  nreplacement = nrow(replacement)
  replacecol = replacement[[colname]]
  for (r in 1:nreplacement){
    test = str_replace_all(tolower(OCol), "[[:punct:]]|[:space:]", "") == str_replace_all(tolower(replacement$In[r]), "[[:punct:]]|[:space:]", "")
    ICol[test] <- replacecol[r]
  }
  ICol
}
RemoveOther <- function(ICol,OCol,NoneCol)
{
  test <- !is.na(ICol) | str_replace_all(tolower(NoneCol), "[[:punct:]]|[:space:]", "") == "none"
  OCol[test] <- NA
  OCol
}
RemoveOther2 <- function(ICol,OCol,NCol,NoneCol)
{
  test <- !is.na(ICol) | !is.na(NCol) | str_replace_all(tolower(NoneCol), "[[:punct:]]|[:space:]", "") == "none"
  OCol[test] <- NA
  OCol
}

#### Option settings for the code chunks
knitr::opts_chunk$set(echo = FALSE,warning = FALSE, message = FALSE, error=TRUE, results="hide")
```

```{r specialfunctions, include=FALSE}
source('subfunctions.r')
```

# General Information and Management

## Respondents countries Q2

The countries of origin of the respondents. Additional grouping depending on the type of institutions.

```{r countries, echo=FALSE, fig.height = 4, fig.width = 7}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")
  
PlotData <- SurveyData %>% select(Q2_1,Q4_1) %>% mutate(Q2_1 = str_replace_all(Q2_1, "United Kingdom of Great Britain and Northern Ireland", "UK")) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(Country=Q2_1, Type=Q4_1) %>% mutate(Country = fct_infreq(Country), Type = factor(Type,levels=TypeOrder)) %>% group_by(Country,Type) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count) 

p <- ggbarplot(PlotData, "Country", "Count",
  fill = "Type", color = "Type", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, lab.nb.digits = 0,
  orientation = "horiz",ylab = "Number per country", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Institutions")
```

## Type of institution Q4

The type of institutions of the respondents.

```{r institution, echo=FALSE, fig.height = 5, fig.width = 6}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")

PlotData <- SurveyData %>% select(Q4_1) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(Institutions=Q4_1) %>% mutate(Institutions = factor(Institutions,levels=TypeOrder)) %>% group_by(Institutions) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = paste0(format(Freq,digits=1),"%"))

p <- ggpie(PlotData, "Freq", 
   fill = "Institutions",label = "labs", size = 1,
   lab.pos = "in", lab.font = "white", color = "white", palette = "Paired")
ggpar(p,legend.title = "Institutions",tickslab = FALSE)

TableData <- SurveyData %>% filter(str_detect(Q4_1, "Other")) %>% select(Q4_2) %>% rename(OtherInstitutions=Q4_2)
doTable(TableData,c("Other institutions"))
```

## 3DGA patient throughput Q5

The subjects or patients throughput for each type of institutions. This is for instrumented (i.e. 3DGA) gait analysis in the last five years.

```{r throughput3DGA, echo=FALSE, fig.height = 4, fig.width = 7}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")
ThroughputOrder <- c("<100","100-200","200-500","500-1000",">1000")

PlotData <- SurveyData %>% select(Q5_1,Q4_1) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(Throughput=Q5_1, Type=Q4_1) %>% mutate(Throughput = factor(Throughput,levels=ThroughputOrder), Type = factor(Type,levels=TypeOrder)) %>% group_by(Throughput,Type) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)

p<- ggbarplot(PlotData, "Throughput", "Count",
  fill = "Type", color = "Type", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of centres per 3DGA throughput range in the last five years", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Institutions")
```

## Video patient throughput Q6

The subjects or patients throughput for each type of institutions. This is for video only assessment in the last five years.

```{r throughputvideo, echo=FALSE, fig.height = 4, fig.width = 7}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")
ThroughputOrder <- c("<100","100-200","200-500","500-1000",">1000")
PlotData <- SurveyData %>% select(Q6_1,Q4_1) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(Throughput=Q6_1, Type=Q4_1) %>% mutate(Throughput = factor(Throughput,levels=ThroughputOrder), Type = factor(Type,levels=TypeOrder)) %>% group_by(Throughput,Type) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count) %>% drop_na()
  # for tabular results add: %>% mutate(TCount = sum(Count)) %>% pivot_wider(names_from = Type,values_from = Count, values_fill = 0)

p<-ggbarplot(PlotData, "Throughput", "Count",
  fill = "Type", color = "Type", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of centres per video-only throughput range in the last five years", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Institutions")
```

## Main age of patients Q7

The main age categories of subjects or patients seen by the respondents (overall).

```{r agepatients, echo=FALSE, fig.height = 5, fig.width = 6}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")
AgeOrder <- c("Children","Adults","Both")

PlotData <- SurveyData %>% select(Q7_1,Q4_1) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(PatientAge=Q7_1, Type=Q4_1) %>% mutate(PatientAge = factor(PatientAge,levels=AgeOrder), Type = factor(Type,levels=TypeOrder)) %>% group_by(PatientAge) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = paste0(format(Freq,digits=1),"%")) %>% drop_na()
  # for tabular results add: %>% mutate(TCount = sum(Count)) %>% pivot_wider(names_from = Type,values_from = Count, values_fill = 0)

p<-ggpie(PlotData, "Count", label = "labs", size = 1,
   lab.pos = "in", lab.font = "white", color = "white",
   fill = "PatientAge", palette = "Paired")
ggpar(p,legend.title = "Main patient group",tickslab = FALSE)
```

## Main categories, neurological Q8

The main categories of patients with a neurological diagnosis (multiple choices possible).

```{r categorypatientsneuro, echo=FALSE, fig.height = 7, fig.width = 15}
Q8replacement<- read.xlsx(xlsxFile = datafile, sheet = "Other modifications", cols = 2:4, rows= 11:42)
SurveyData$Q8_11 <- SurveyData$Q8_10
SurveyData$Q8_12 <- OtherModifyCol(SurveyData$Q8_11,SurveyData$Q8_11,Q8replacement,colname = 'New')
SurveyData$Q8_13 <- OtherModifyCol(SurveyData$Q8_10,SurveyData$Q8_10,Q8replacement,colname = 'Modified')

AgeOrder <- c("Children","Adults","Both")
PlotData <- SurveyData %>% select(Q7_1,starts_with("Q8")) %>% select(-Q8_10,-Q8_11,-Q8_13) %>% rename(PatientAge=Q7_1) %>% mutate(PatientAge = factor(PatientAge,levels=AgeOrder)) %>% pivot_longer(starts_with("Q8"),values_to = "Diagnosis") %>% drop_na() %>% mutate(Diagnosis = fct_infreq(Diagnosis))%>% group_by(Diagnosis,PatientAge) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)


p <- ggbarplot(PlotData, "Diagnosis", "Count",
  fill = "PatientAge", color = "PatientAge", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )

ggpar(p,legend.title = "Main neurologic patient group")

TableData <- SurveyData %>% select(Q8_13) %>% drop_na()
doTable(TableData,col.names=c("Other patient category neuro"))
```

## Main categories, non-neurological Q9

The main categories of patients with a non-neurological diagnosis (multiple choices possible).

```{r categorypatientsNneuro, echo=FALSE, fig.height = 5, fig.width = 9}
Q9replacement<- read.xlsx(xlsxFile = datafile, sheet = "Other modifications", cols = 2:4, rows= 43:77)
SurveyData$Q9_8 <- SurveyData$Q9_7
SurveyData$Q9_9 <- OtherModifyCol(SurveyData$Q9_8,SurveyData$Q9_8,Q9replacement,colname = 'New')
SurveyData$Q9_10 <- OtherModifyCol(SurveyData$Q9_7,SurveyData$Q9_7,Q9replacement,colname = 'Modified')

AgeOrder <- c("Children","Adults","Both")
PlotData <- SurveyData %>% select(Q7_1,starts_with("Q9")) %>% select(-Q9_7,-Q9_8,-Q9_10) %>% rename(PatientAge=Q7_1) %>% mutate(PatientAge = factor(PatientAge,levels=AgeOrder)) %>% pivot_longer(starts_with("Q9"),values_to = "Diagnosis") %>% drop_na() %>% mutate(Diagnosis = fct_infreq(Diagnosis))%>% group_by(Diagnosis,PatientAge) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)


p <- ggbarplot(PlotData, "Diagnosis", "Count",
  fill = "PatientAge", color = "PatientAge", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Main non-neurological patient groups")

TableData <- SurveyData %>% select(Q9_10) %>% drop_na()
doTable(TableData,col.names=c("Other patient category non-neuro"))
```

## Main population, neurological Q10

Main categories, but only one choice of diagnosis (neuro) possible.

```{r poppatientneuro, echo=FALSE, fig.height = 5, fig.width = 9}
Q10replacement<- read.xlsx(xlsxFile = datafile, sheet = "Other modifications", cols = 2:4, rows= 78:94)

SurveyData$Q10_3 <- SurveyData$Q10_2
SurveyData$Q10_4 <- OtherModifyCol(SurveyData$Q10_3,SurveyData$Q10_3,Q10replacement,colname = 'New')
SurveyData$Q10_5 <- OtherModifyCol(SurveyData$Q10_2,SurveyData$Q10_2,Q10replacement,colname = 'Modified')
SurveyData$Q10_0 <- RemoveOther2(SurveyData$Q10_5,SurveyData$Q10_1,SurveyData$Q10_4,SurveyData$Q10_2)

AgeOrder <- c("Children","Adults","Both")
PlotData <- SurveyData %>% select(Q10_0,Q10_4,Q7_1) %>% rename(PatientAge=Q7_1) %>% mutate(PatientAge = factor(PatientAge,levels=AgeOrder)) %>% pivot_longer(starts_with("Q10"),values_to = "Diagnosis") %>% mutate(Diagnosis = fct_infreq(Diagnosis))%>% group_by(Diagnosis,PatientAge) %>% summarise(Count = n()) %>% drop_na() %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)

p <- ggbarplot(PlotData, "Diagnosis", "Count",
  fill = "PatientAge", color = "PatientAge", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Main population, neuro")


TableData <- SurveyData %>% select(Q10_5) %>% drop_na()
doTable(TableData,col.names=c("Other main population"))
```

## Main population, non-neurological Q11

Main categories, but only one choice of diagnosis (non-neuro) possible.

```{r poppatientNneuro, echo=FALSE, fig.height = 4, fig.width = 9}
Q11replacement<- read.xlsx(xlsxFile = datafile, sheet = "Other modifications", cols = 2:4, rows= 95:119)

SurveyData$Q11_3 <- SurveyData$Q11_2
SurveyData$Q11_3 <- OtherModifyCol(SurveyData$Q11_3,SurveyData$Q11_3,Q11replacement,colname = 'New')
SurveyData$Q11_4 <- OtherModifyCol(SurveyData$Q11_2,SurveyData$Q11_2,Q11replacement,colname = 'Modified')
SurveyData$Q11_0 <- RemoveOther2(SurveyData$Q11_4,SurveyData$Q11_1,SurveyData$Q11_3,SurveyData$Q11_2)

AgeOrder <- c("Children","Adults","Both")
PlotData <- SurveyData %>% select(Q11_0,Q11_3,Q7_1) %>% rename(PatientAge=Q7_1) %>% mutate(PatientAge = factor(PatientAge,levels=AgeOrder)) %>% pivot_longer(starts_with("Q11"),values_to = "Diagnosis") %>% mutate(Diagnosis = fct_infreq(Diagnosis))%>% group_by(Diagnosis,PatientAge) %>% summarise(Count = n()) %>% drop_na()%>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)


p <- ggbarplot(PlotData, "Diagnosis", "Count",
  fill = "PatientAge", color = "PatientAge", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )

ggpar(p,legend.title = "Main population, non-neuro")

TableData <- SurveyData %>% select(Q11_4) %>% drop_na()
doTable(TableData,col.names=c("Other main population non neuro"))
```

## Reason to use CGA Q12

Level of agreement of the respondents with the use of 3DGA for the following four reasons to conduct a gait analysis. 

```{r reason4CGA, echo=FALSE, fig.height = 5, fig.width = 11}
PlotData <- SurveyData %>% select(starts_with("Q12")) %>% pivot_longer(everything(),values_to = "Often") %>% mutate(Often = fct_inseq(as.factor(Often),ordered=TRUE)) %>% group_by(name,Often) %>% drop_na()%>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count))

mpalette <- get_palette(c("#a80000", "#fcf807", "#04ba07"), 11)
p<-ggbarplot(PlotData, "name", "Freq",
  fill = "Often", color="Often", palette = mpalette,
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "Percentage of respondents who used CGA for ... ", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=c("Decide on treatment","Determine treatment effect - short term","Determine treatment effect - long term","Follow up")) + scale_fill_manual(name= "Level of agreement",values=mpalette,labels=c("0-Never","1","2","3","4","5","6","7","8","9","10-allways"))+ guides(color = "none")

print(p)
```

## Cost of CGA Q13, per type of institutions

Approximate cost charged for 3DGA, sub-grouped per type of institutions.

```{r costCGA, echo=FALSE, fig.height = 4, fig.width = 8}
TypeOrder <- c("Other","Rehabilitation center","Private Hospital","Public Hospital","University Hospital","University")
CosttOrder <- c("No costs","1-100","100-200","200-500","500-1000","1000-1500","1500-2000",">2000","No reply")

PlotData <- SurveyData %>% select(Q13,Q4_1) %>% mutate(Q4_1 = str_replace_all(Q4_1, " \\(please specify\\)", "")) %>% mutate(Q4_1 = str_replace_all(Q4_1, "Clinical", "Other")) %>% rename(Cost=Q13, Type=Q4_1) %>% mutate(Cost = factor(replace_na(Cost,c("No reply")),levels=CosttOrder), Type = factor(Type,levels=TypeOrder)) %>% group_by(Cost,Type) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)

p<-ggbarplot(PlotData, "Cost", "Count",
  fill = "Type", color = "Type", palette = "Paired",
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "Cost charged to conduct a CGA", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Type of institution")
```

## Cost of CGA Q13, per countries

Approximate cost charged for 3DGA, sub-grouped per country.

```{r costCGACountries, echo=FALSE, , fig.height = 5, fig.width = 11}
CosttOrder <- c("No reply","No costs","1-100","100-200","200-500","500-1000","1000-1500","1500-2000",">2000")
PlotData <- SurveyData %>% select(Q13,Q2_1) %>% mutate(Q2_1 = str_replace_all(Q2_1, "United Kingdom of Great Britain and Northern Ireland", "UK")) %>% rename(Cost=Q13, Country=Q2_1) %>% mutate(Country = fct_infreq(Country),Cost = factor(replace_na(Cost,c("No reply")),levels=CosttOrder)) %>% group_by(Country,Cost) %>% summarise(Count = n()) %>% mutate(lab_ypos = cumsum(Count) - 0.5 * Count)

mpalette <- c("gray",get_palette(c("#04ba07", "#fcf807", "#a80000"), 8))
p<-ggbarplot(PlotData, "Country", "Count",
  fill = "Cost", color = "Cost", palette = mpalette,
  label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",ylab = "Number of respondents", xlab = "Countries", position = position_stack(reverse=TRUE)) +
  geom_text(
    aes(y = lab_ypos, label = Count, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Cost charged to conduct a CGA")
```

## Use of published guidelines Q14

Do the respondents observe existing published guidelines or accreditation process. The four guidelines were:

* CMLA: Commission for Motion Laboratory Accreditation (USA)
* SENIAM: Surface EMG for non-invasive assessment of muscles (EU)
* SIAMOC: Position paper on gait analysis in clinical practice (Italy)
* CMAS: Clinical Movement Analysis Society (UK)

```{r guidelinesuse, echo=FALSE, fig.height = 4, fig.width = 8}
UseFactor <- c("No answer","No","Partially","Competely")
Guidelines <- c("CMAS","SIAMOC","SENIAM","CMLA")
PlotData <- SurveyData %>% select(starts_with("Q14")) %>% select(-Q14_6,-Q14_5) %>% pivot_longer(starts_with("Q14"),values_to = "Guidelines") %>% mutate(Guidelines = replace_na(Guidelines,UseFactor[1])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = paste0(format(freq,digits=1),"%")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)


mpalette <- c("#9c9c9c", "#0f0f0f", "#e6a01e", "#1c9928")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Guidelines", color = "Guidelines", label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=Guidelines) + scale_fill_manual(name= "Guidelines",values=mpalette) + scale_color_manual(name= "Guidelines",values=mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "Use guideline: ")

TableData <- SurveyData %>% select(Q14_6) %>% drop_na()
doTable(TableData,col.names=c("Other guidelines used"))
```

## Societies and people Q15

Country of work of the persons in the laboratory and the scientific societies there are affiliated.

```{r peoplesocieties, echo=FALSE, fig.height = 4, fig.width = 8}

Societies <- c("ESMAC","SMALL","GAMMA","SIAMOC","CMAS","SOFAMEA")

Countries <- c("Austria","Belgium","France","Germany","Greece","Ireland","Israel","Italy","Lebanon","Netherlands","Poland","Switzerland","Turkey","UK")
CountryColours <- c("#92479b","#fec938","#204EA2","#080504","#86D3DE","#366e4f","#5d3d21","#14a4dd","#C3D941","#F47832","#C96C92","#ED272A","#827976","#ffffff")

PlotData <- SurveyData %>% select(Q2_1,starts_with("Q15")) %>% select(-Q15_7) %>% mutate(Q2_1 = str_replace_all(Q2_1, "United Kingdom of Great Britain and Northern Ireland", "UK")) %>% pivot_longer(starts_with("Q15"),names_to = "Society",values_to = "Nb") %>% drop_na() %>% rename(Country=Q2_1) %>% filter(Country !='Norway') %>% group_by(Society, Country) %>% summarise(N = sum(Nb)) %>% mutate(Society = recode(Society, "Q15_1" = "ESMAC", "Q15_2" = "SIAMOC", "Q15_3"="CMAS", "Q15_4"="GAMMA", "Q15_5"="SOFAMEA", "Q15_6" = "SMALL")) %>% mutate(Society = factor(Society,levels=Societies)) %>% mutate(labs = ifelse(N>2,format(N,digits=1),"")) %>% mutate(lab_ypos = cumsum(N) - 0.5 * N) %>% mutate(labsUK = ifelse(Country == "UK" & N>0,format(N,digits=1),""))

p<-ggbarplot(PlotData, "Society", "N",
  fill = "Country", label = FALSE, orientation = "horiz",xlab = "", ylab = "Number of people affiliated with each society", position = position_stack(reverse=TRUE))
p <- p + scale_fill_manual(name= "Country", values = CountryColours)  +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Type"),
    color = "white"
  ) +
  geom_text(
    aes(y = lab_ypos, label = labsUK, group = "Type"),
    color = "black"
  )
ggpar(p,legend.title = "Country: ")

# TableData <- SurveyData %>% select(Q15_7) %>% drop_na()
# doTable(TableData,col.names=c("Other societies"))
```

## License to conduct CGA Q16

Is there a need for a special professional license to conduct 3DGA in the countries of the respondents

```{r license4CGA, echo=FALSE, fig.height = 4, fig.width = 8}
YesNoOrder <- c("Yes","No","There is no licence to conduct CGA in my country")
PlotData <- SurveyData %>% select(Q16,Q2_1) %>% drop_na() %>% mutate(Q2_1 = str_replace_all(Q2_1, "United Kingdom of Great Britain and Northern Ireland", "UK")) %>% mutate(Q16 = str_replace_all(Q16, "There is no licence to conduct CGA in my country", "No licence in my country")) %>% rename(Licence=Q16, Countries=Q2_1) %>% mutate(Countries = fct_infreq(Countries),Licence = factor(Licence,levels=YesNoOrder)) %>% group_by(Countries,Licence) %>% summarise(n = n()) %>% mutate(Freq = 100* n/sum(n)) %>% mutate(Percent = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq) %>% mutate(lab_ypos = ifelse(lab_ypos > 50,60, lab_ypos))

mpalette <- c("#1c9928","#ba0404","#9c9c9c") 
p<-ggbarplot(PlotData, "Countries", "Freq", color="Licence", fill="Licence",
             label = NULL, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position =  position_stack(reverse = TRUE))
p <- p  + scale_fill_manual(name= "Licence",values=mpalette) + 
          scale_color_manual(name= "Licence",values=mpalette) +
          guides(fill = guide_legend(reverse = FALSE)) +
          guides(color = guide_legend(reverse = FALSE)) +
          geom_text(
            aes(y = lab_ypos, label = Percent, group = "Licence"),
            color = "white"
          )

ggpar(p,legend.title = "Licence to conduct a CGA")
```

## People and disciplines Q17

```{r peopleanddisciplines, echo=FALSE, fig.height = 4, fig.width = 8}
LabelProfessions<- c("Physiotherapist","Ortho. surgeon","PRM doctor","Sport scientist","Biomed. eng.","Clin. technologist","Neurologist","Orthotist","Prosthetist","Podiatrist","Pediatrician","Researcher")
Colors <- c("#f1c232","#741b47","#0b5394","#b6d7a8", "#38761d","#6aa84f","#674ea7","#ffffff","#ffffff","#ffffff", "#3c78d8","#e69138")
ProfessionColor <- data.frame(LabelProfessions,Colors)

PlotData <- SurveyData %>% select(starts_with("Q17")) %>% select(-Q17_13)  %>% mutate(across(everything(),as.numeric)) %>% pivot_longer(starts_with("Q17"),values_to = "number",names_prefix = "Q17_",names_transform = list(name = as.integer))  %>% drop_na() %>% mutate(LabelProfessions=factor(name,labels=LabelProfessions)) %>% group_by(LabelProfessions)
OrderedCategories <- PlotData %>% summarise(Order = mean(number)) %>% merge(ProfessionColor) %>% arrange(desc(Order))

p <- ggboxplot(PlotData,x="LabelProfessions",y="number", 
               xlab = "Professions", ylab = "Numbers per respondent",
               order = OrderedCategories$LabelProfessions,fill = "LabelProfessions",palette = OrderedCategories$Colors,
               outlier.shape = NA) + coord_flip()
p + 
  geom_point(size = 1.5, alpha = 0.2, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
  theme(legend.position = "none")

TableData <- SurveyData %>% select(Q17_13) %>% drop_na()
doTable(TableData,col.names=c("Other professions"))

```

## Head of lab CGA Q18 

```{r headoflab, echo=FALSE, fig.height = 3, fig.width = 10}

LabelProfessions<-c("Researcher","Biomed. eng.","Clin. technologist","Sport Scientist","Physiotherapist","Pediatrician","PRM doctor","Neurologist","Ortho. surgeon","No answer")
mpalette <- c("#e69138", "#38761d", "#6aa84f", "#b6d7a8","#f1c232", "#3c78d8", "#0b5394", "#674ea7","#741b47", "#999999")

HeadProf <- c("Technical","Medical")
PlotData <- SurveyData %>% select(starts_with("Q18")) %>% select(-Q18_3) %>% pivot_longer(starts_with("Q18"),values_to = "Profession") %>% mutate(Profession = recode(Profession,"Bioengineer"=LabelProfessions[2],"Clinical technologist"=LabelProfessions[3],"Orthopaedic surgeon"=LabelProfessions[9])) %>% mutate(Head = recode(name, "Q18_1"="Medical","Q18_2"="Technical")) %>% mutate(Profession = factor(replace_na(Profession,"No answer"),levels = LabelProfessions)) %>% group_by(Head,Profession)  %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(Percent = ifelse(freq>3.5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) 



p<-ggbarplot(PlotData, "Head", "freq", fill = "Profession",color = "Profession",palette=mpalette,
             label = NULL, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE)) +
          geom_text(
            aes(y = lab_ypos, label = Percent, group = "Head"),
            color = "white"
          )

ggpar(p,legend.title = "Technical and medical leaders")

```

## Gait lab staff involved in the task of Q19  

```{r taskanddisciplines, echo=FALSE, fig.height = 4, fig.width = 8}
tasks_name=c("Decision to perform the CGA","Physical examination","Data collection","Data processing","Data reduction/analysis","Data interpretation","Clinical decision-making")
PlotData <- SurveyData %>% select(starts_with("Q19"))  %>% select(-Q19_8) %>% pivot_longer(everything(),values_to = "value",names_to = "QTask",names_prefix = "Q19_", names_transform = list(QTask = as.integer))%>% mutate(NameTask = factor(QTask,labels = tasks_name),tasks = factor(ifelse(is.na(value),"No","Yes"),levels = c("Yes","No"))) %>% group_by(NameTask,tasks)  %>% summarise(n = n())%>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>3.5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)                                                                           
mpalette <- c("#1c9928","#ba0404")                                                                                           

p<-ggbarplot(PlotData, "NameTask", "freq", fill = "tasks", color="tasks", palette=mpalette,
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE)) + 
             scale_x_discrete(limits = rev(levels(PlotData$NameTask)))

ggpar(p,legend.title = "Do tasks: ")

TableData <- SurveyData %>% select(Q19_8) %>% drop_na()
doTable(TableData,col.names=c("Other tasks"))

```

## Frequency of training Q20 
How often do staff receive training in the following tasks?

```{r frequencyoftraining, echo=FALSE, fig.height = 4, fig.width = 10}

UseFactor <- c("At least once a year","At least once each 2 years","At least once each 5 years","Only at the opening of the lab","Randomly","Never","Not used in my lab","No answer")
tasks_name <- c("Physical exam","Marker placement","Surface EMG placement","Fine-wire EMG placement","Data collection","Data reduction/analysis","Data interpretation","Clinical recommendations")
PlotData <- SurveyData %>% select(starts_with("Q20")) %>% select(-Q20_10,-Q20_9) %>% pivot_longer(starts_with("Q20"),values_to = "Period",names_to = "Task",names_prefix = "Q20_", names_transform = list(Task = as.integer))%>% mutate(NameTask = factor(Task,labels = tasks_name)) %>% replace_na(list(Period="No answer")) %>% filter(!grepl("Other", Period, fixed = TRUE)) %>% mutate(Period = factor(Period,levels=UseFactor)) %>% group_by(NameTask,Period) %>%  summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) 

# 
mpalette <- c("#1C9928", "#81A814", "#e6a01e", "#FFC500", "steelblue","black","gray60","gray70")
p<-ggbarplot(PlotData, "NameTask", "freq", fill = "Period", color = "Period", palette = mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE)) 

p <- p  + scale_x_discrete(labels=tasks_name) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")
ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q20_10) %>% drop_na()
doTable(TableData,col.names=c("Other training"))
```

## Testing consistency Q21 
How often do you test within and between consistency of the personnel for the following tasks?

```{r testingconsistency, echo=FALSE, fig.height = 4, fig.width = 10}
UseFactor <- c("At least once a year","At least once each 2 years","At least once each 5 years","Only at the opening of the lab","Randomly","Never","Not used in my lab")
tasks_name <- rev(c("Physical exam","Marker placement","Surface EMG placement","Fine-wire EMG placement","Data collection","Data reduction/analysis","Data interpretation","Clinical recommendations"))

PlotData <- SurveyData %>% select(starts_with("Q21")) %>% select(-Q21_10) %>% select(-Q21_9) %>% pivot_longer(starts_with("Q21"),values_to = "Period",names_to = "Task",names_prefix = "Q21_", names_transform = list(Task = as.integer))%>% mutate(NameTask = factor(Task,labels = tasks_name)) %>% replace_na(list(Period="No answer")) %>% filter(!grepl("Other", Period, fixed = TRUE)) %>% mutate(Period = factor(Period,levels=UseFactor)) %>% group_by(NameTask,Period) %>%  summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) 

# 
mpalette <- mpalette <- c("#1C9928", "#81A814", "#e6a01e", "#FFC500", "steelblue","black","gray60","gray70")
p<-ggbarplot(PlotData, "NameTask", "freq", fill = "Period", color = "Period", palette = mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE)) 

p <- p  + scale_x_discrete(labels=tasks_name) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")
ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q21_10) %>% drop_na()
doTable(TableData,col.names=c("Other consistency tests"))

```

## Time to conduct CGA Q22 
What time (in minutes) allocation do you allow for the following tasks related to the CGA? 

```{r time4CGA, echo=FALSE, fig.height = 4, fig.width = 8}

NameData <- LabelData %>% filter(Q=="Q22")%>%select(num,ShortAnswers)%>%filter(num!="09")
Colors <- rev(c("Tomato","Blue","RoyalBlue","CornFlowerBlue", "SteelBlue","Gold","Coral","Salmon"))
TaskColor <- data.frame(NameData,Colors)

PlotData <- SurveyData %>% select(starts_with("Q22")) %>% select(-Q22_9)%>% pivot_longer(starts_with("Q22"),values_to = "Time",names_to = "Task",names_prefix = "Q22_", names_transform = list(Task = as.integer)) %>% mutate(NameData = factor(Task,labels = TaskColor$ShortAnswers)) %>% drop_na()

p <- ggboxplot(PlotData,x="NameData",y="Time",
               fill = "NameData",xlab = "", ylab = "Time (minutes)", outlier.shape = NA,
               order = rev(TaskColor$ShortAnswers),palette = rev(TaskColor$Colors)) + 
  scale_y_continuous(limits=c(0,120))
ggpar(p,legend = "none",orientation = "horizontal")+
geom_point(size = 1, alpha = 0.2, position = position_jitter(width = 0.2, height = 0, seed = 1))

```

# Facility and Instrumentation

## Physical dimensions of the lab Q23  
What are the physical dimensions of your gait lab? Size of room (in metres)

```{r PhysDimLab, echo=FALSE, fig.height = 4, fig.width = 8}
Dimensions <- c("Length","Width","Height")
PlotData <- SurveyData %>% select(starts_with("Q23")) %>% pivot_longer(starts_with("Q23"),values_to = "Size",names_to = "Dim",names_prefix = "Q23_", names_transform = list(Dim = as.integer)) %>% mutate(DimName = factor(Dim,labels = Dimensions)) %>% drop_na()

p <- ggboxplot(PlotData,x="DimName",y="Size",
               fill = "DimName",xlab = "", ylab = "Size (m)",outliers = NA, outlier.shape = NA) +
      scale_y_continuous(limits = c(0,25))

ggpar(p,legend = "none") +
geom_point(size = 1.5, alpha = 0.2, position = position_jitter(width = 0.2, height = 0, seed = 1))
```

## Facilities of the lab Q24 
Do your gait lab facilities include the following?

```{r facilities, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("Access for disabled patients", "Controlled access for security purposes during patient assessment","A minimum 7 metre walking space for gait data collection", "Room temperature adjustable thermostat","A quiet and non-distracting environment","A designated area where the patient can both change and be examined in privacy", "Patient toilet facilities, including toilet for the disabled", "Adequate seating facilities available for patients and families", "Staff hand washing facilities","Non-slip","Level and obstacle free floor", "Daily floor cleaning", "Examination couch and covers which are cleaned between each patient")
ShQuestions =c("Access for disabled patients","Controlled access to the room","Minimum 7m walking distance","Controlled room Temperature","Quiet environment","Seperated change/examination room","Disabled toilets","Adequate seating options","Staff hand washing facilities","Non-slippery floor","Leveled floor","Daily floor cleaning")

PlotData <- SurveyData %>% select(starts_with("Q24")) %>% select(-Q24_13) %>% pivot_longer(starts_with("Q24"),values_to = "Response",values_transform = list(Response = as.factor)) %>% drop_na() %>% mutate(Response = as.factor(Response)) %>% group_by(name,Response) %>% summarise(n = n()) %>% mutate(freq = 100* n/sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#ba0404","#1C9928")                                                                                           

p<-ggbarplot(PlotData, "name", "freq", fill = "Response", color="Response", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%")

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Facilities",values=mpalette) + 
          scale_color_manual(name= "Facilities",values=mpalette) +
          guides(fill = guide_legend(reverse = TRUE)) +
          guides(color = guide_legend(reverse = TRUE))

ggpar(p,legend.title = "Facilities: ")

TableData <- SurveyData %>% select(Q24_13) %>% drop_na()
doTable(TableData,col.names=c("Other facilities"))
```

## CGA equipment Q25 
Which equipment do you use for CGA and how much of each device do you use in your lab? Please type 0 if none. (The answers to this question were text only and no graphics were created.)

## CE medical marking Q26 
Which equipment used in your lab for CGA has a medical CE marking?

```{r CEmedicalmarking, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("Instrumented Treadmill","Treadmill","GPS tracking","Activity monitor","Oxygen consumption system","Inertial sensors","Plantar pressure insoles","Plantar pressure plate","Fine-Wire Electromyography","Electromyography","Force plates","Stereophotogrammetric system","Video camera")
Order_question=c("Q26_13","Q26_12","Q26_11","Q26_10","Q26_9","Q26_8","Q26_7","Q26_6","Q26_5","Q26_4","Q26_3","Q26_2","Q26_1")
PlotData <- SurveyData %>% select(starts_with("Q26")) %>% select(-Q26_14) %>% pivot_longer(starts_with("Q26"),values_to = "Response",values_transform = list(Response = as.factor)) %>% mutate(Response = recode(Response, "Not used in my lab" = "Not used", "I do not know" = "I don't know", "No"="No", "Yes"="Yes")) %>% drop_na() %>% group_by(name,Response) %>% summarise(n = n()) %>% mutate(Freq = 100* n/sum(n)) %>% mutate(labs = ifelse(Freq>10,paste0(format(Freq,digits=1),"%"),""))

PlotData$Response <- factor(PlotData$Response,levels = c("Not used","I don't know","No","Yes"))

mpalette <- c("#0f0f0f","#9c9c9c","#ba0404","#1C9928") 

p<-ggbarplot(PlotData, "name", "Freq", fill = "Response", color="Response", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", order = Order_question)

p <- p  + scale_x_discrete(labels=Questions) + 
          scale_fill_manual(name= "Medical CE",values=mpalette) + 
          scale_color_manual(name= "Medical CE",values=mpalette) +
          guides(fill = guide_legend(reverse = TRUE)) +
          guides(color = guide_legend(reverse = TRUE))

ggpar(p,legend.title = "Medical CE")

TableData <- SurveyData %>% select(Q26_14) %>% drop_na()
doTable(TableData,col.names=c("Other devices"))

```

## Measure Frequency of device Q27 
What is the measurement frequency in Hertz of acquisition of the equipment that you use in your lab for CGA? Please type 0 if not used in my lab.

```{r DeviceFrequency, echo=FALSE, fig.height = 5, fig.width = 10}
Questions = rev(c("Treadmill","GPS","Activity monitor","Inertial sensors","Plantar pressure insoles","Plantar pressure plate","Fine-Wire Electromyography","Electromyography","Force plates","Stereophotogrammetric system","Video camera"))

PlotData <- SurveyData %>% select(starts_with("Q27")) %>% select(-Q27_12) %>% pivot_longer(starts_with("Q27"),values_to = "Frequency",names_to = "Question",names_prefix = "Q27_", names_transform = list(Question = as.integer)) %>% mutate(QuestionName = factor(Question,labels = Questions)) %>% drop_na() %>% mutate(logFreq = log10(Frequency))

gbreaks = c(10,50,100,200,500,1000,2000,4000)
p <- ggviolin(PlotData,x="QuestionName",y="logFreq", fill = "QuestionName",
              trim = TRUE,
              xlab = "", ylab = "Frequency (Hz) - Log Scale",order = rev(levels(PlotData$QuestionName)), outlier.shape = NA) +
  scale_y_continuous(breaks = log10(gbreaks),labels = gbreaks) +
   coord_flip()
  
ggpar(p,legend = "none") +
geom_point(size = 1.4, alpha = 0.25, position = position_jitter(width = 0.2, height = 0.0, seed = 1))
```

## Synchronization of devices Q28 
Which of the following devices of your lab are synchronized to each other?

```{r synchronizedDevice, echo=FALSE, fig.height = 5, fig.width = 8}
devices= rev(c("Video camera","Stereophotogrammetric system","Force plates","Surface Electromyography","Fine-Wire Electromyography","Plantar pressure plate","Plantar pressure insoles","Inertial sensors","Oxygen consumption system","Activity monitor","Treadmill","Instrumented Treadmill")) # instead of reverting in Excel I revert the data here

Respondent <- SurveyData %>% select(starts_with("Q28")) %>% select(-Q28_14,-Q28_11) %>% mutate(test = rowSums(is.na(.))/ncol(.)) %>% summarise(n = sum(.$test != 1))

PlotData <- SurveyData %>% select(starts_with("Q28")) %>% select(-Q28_14,-Q28_11) %>% pivot_longer(starts_with("Q28"),values_to = "devices")  %>% group_by(devices) %>% drop_na()  %>% summarise(n = n()) %>% mutate(freq = 100 * n / Respondent$n) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% arrange(desc(freq))

mpalette <- get_palette("lancet",12)

p<-ggbarplot(PlotData, "devices", "freq", fill = "devices", color = "devices", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", palette = mpalette ,position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "", legend = "none")


TableData <- SurveyData %>% select(Q28_14) %>% drop_na()
doTable(TableData,col.names=c("Other devices synchronized"))

```

## Data collected Q29
How often do you collect the following datasets during CGA?  

```{r DeviceUsedForCGA, echo=FALSE, fig.height = 5, fig.width = 8}

UseFactor <- c("Always","Often","Regularly","Sometimes","Never")
Guidelines <- c("Oxygen consumption","Inertial sensors","Questionnaires","Physical exam","Plantar pressure","Fine-wire EMG","Surface EMG","GRFs ( video vector)","Foot multi-segment kinematics","Trunk and/or arm kinematics","Lower limb kinetics","Lower limb kinematics","Video footage")
PlotData <- SurveyData %>% select(starts_with("Q29")) %>% select(-Q29_14) %>% pivot_longer(starts_with("Q29"),values_to = "Guidelines") %>% mutate(Guidelines = replace_na(Guidelines,UseFactor[5])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#81A814", "#e6a01e", "#FFC500", "black")
p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) +
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

```

## Additional measurements to CGA Q30
Do you use additional measurements on top of the standard CGA for specific treatments and/or pathologies? If so, which? 

```{r Additional measurement, echo=FALSE, fig.height = 4, fig.width = 7}

PlotData <- SurveyData %>% select(starts_with("Q30"))  %>% select(-Q30_12)

PlotData <- PlotData %>% pivot_longer(starts_with("Q30"),values_to = "devices") %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(devices) %>% drop_na()  %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = (freq) - 0.5 * freq) %>% arrange(desc(freq))

mpalette <- get_palette("lancet",12)

p<-ggbarplot(PlotData, "devices", "freq", fill = "devices", color = "devices",palette = mpalette,
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "", legend = "none")


TableData <- SurveyData %>% select(Q30_12) %>% drop_na()
doTable(TableData,col.names=c("Other devices used"))
```

## Minimal number of gait cycles Q31
What is the minimal number of gait cycles that you consider it necessary to collect to satisfactorily interpret CGA for (please type 0 if none)? 

```{r MumberOfGaitCycle, echo=FALSE, fig.height = 4, fig.width = 7}
DataLabel <- c("Spatio-temporal parameters","Kinematics","Kinetics","Surface EMG","Fine-wire EMG","Plantar pressure")

PlotData <- SurveyData %>% select(starts_with("Q31")) %>% mutate(across(everything(),as.numeric)) %>% 
pivot_longer(starts_with("Q31"),values_to = "N")

PlotData[PlotData==250] <- NA # We suppose this value is a mistake

p <- ggboxplot(PlotData,x="name",y="N", fill = "name",xlab = "", ylab = "Number of Gait cycles (N)", outlier.shape = NA) +
               scale_x_discrete(labels=DataLabel) +
               scale_y_continuous(breaks = c(0,2,4,6,8,10,20,30,40,50)) + 
               coord_flip()
#b)   stat_summary(fun=mean, geom = "text", label=Mean) +

ggpar(p,legend = "none") +
geom_point(size = 1, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1))
```

## External technical calibration of systems Q32 
Do an external company (e.g. the manufacturer) perform a technical calibration of the systems used for CGA? 

```{r ExternalCompany_Calibration, echo=FALSE, fig.height = 5, fig.width = 11}
devices= rev(c("Video camera","Stereophotogrammetric system","Force plates","Surface electromyography","Fine-wire electromyography","Plantar pressure plate","Plantar pressure insoles","Inertial sensors","Oxygen consumption system","Activity monitor","GPS","Treadmill","Instrumented Treadmill","Other (please specify)")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Once a year","Once two years","Only at the opening of the lab","On specific request without an established review schedule","Never", "Not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q32")) %>% select(-Q32_15)%>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q32"),values_to = "devices") %>% drop_na() %>% mutate(devices = factor(devices,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,devices) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#81A814", "#FFC500", "steelblue", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "devices", color = "devices", palette = mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=devices) + 
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q32_15) %>% drop_na()
doTable(TableData,col.names=c("Devices calibrated by external company"))
```

## External quality control of systems Q33
Does an external company (e.g. the manufacturer) perform a quality control assessment of the systems used for CGA? 

```{r ExternalCompany_Quality, echo=FALSE, fig.height = 5, fig.width = 11}
devices= rev(c("Video camera","Stereophotogrammetric system","Force plates","Surface electromyography","Fine-wire electromyography","Plantar pressure plate","Plantar pressure insoles","Inertial sensors","Oxygen consumption system","Activity monitor","GPS","Treadmill","Instrumented Treadmill","Other (please specify)")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Once a year","Once two years","Only at the opening of the lab","On specific request without an established review schedule","Never", "Not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q33")) %>% select(-Q33_15)%>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q33"),values_to = "devices") %>% drop_na() %>% mutate(devices = factor(devices,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,devices) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#81A814", "#FFC500", "steelblue", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "devices", color = "devices", label = FALSE, 
             lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=devices) + 
          scale_fill_manual(name= "",values=mpalette) +    
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q33_15) %>% drop_na()
doTable(TableData,col.names=c("Quality control of specified decive by external company"))

```

## CGA documentation Q34
Do you have documentation (written or electronic) in your CGA including the following?

```{r Documentation, echo=FALSE, fig.height = 11, fig.width = 9}

Questions = c("List of current staff employed","List of of training of the staff employed","Protocol to install CGA equipment and software","Protocol to check the quality of your CGA equipment","Protocol to check within and between consistency of the staff - Methods to check consistency","Protocol to check within and between consistency of the staff - Limit of acceptability","Protocol for lab preparation - Calibration","Protocol for lab preparation - Checking equipment","Protocol for patient preparation - Marker placement","Protocol for patient preparation - Marker attachment on the skin","Protocol for patient preparation - Skin preparation for EMG","Protocol for patient preparation - EMG placement","Protocol for patient preparation - EMG attachment on the skin","Protocol for patient preparation - IMU sensor placement/calibration/attachment on the skin","Protocol for data collection - Instructions for patients","Protocol for data collection - Tasks to collect","Protocol for data collection - Number of trials/cycles","Protocol for data collection - Number of cycles on forceplates","Protocol for data collection - Checking of marker trajectories","Protocol for data collection - Checking of EMG","Protocol for data collection - Criteria to categorize a useful or not useful trial","Protocol for data processing including methods and software - Event detection","Protocol for data processing including methods and software - Spatio-temporal data","Protocol for data processing including methods and software - 2D kinematics data","Protocol for data processing including methods and software - Marker trajectory reconstruction (residual, gap filling, etc)","Protocol for data processing including methods and software - Marker labelling","Protocol for data processing including methods and software - Marker filtering","Protocol for data processing including methods and software - EMG (e.g. filtering techniques used, gait timing identification)","Protocol for data processing including methods and software - 3D Kinematics data","Protocol for data processing including methods and software - 3D Kinetics data","Protocol for data processing including methods and software - Plantar Pressure data","Biomechanical model used with potential sources of error in their calculation","Protocol to check data quality","Protocol for physical examination","Protocol for reporting","Protocol for interpretation","Protocol for cleaning the equipment used in CGA","Protocol for data storage (place,backed up, duration)","Protocol for filenames and formats","Protocole for safety procedures, serious adverse events occurring during CGA")

ShQuestions = c("Safety Procedures","Filenames and format","Data storage","Cleaning equipment","Interpretation","Reporting","Physical Examination","Data Quality","Biomechanical model ","Plantar Pressure data","3D Kinetics data","3D Kinematics data","EMG processing","Marker filtering","Marker labelling","Marker reconstruction","2D kinematics data","Spatio-temporal data","Event detection","Validity trial","Check EMG","Check marker trajectories","n cycles on forceplates","n trials/cycles","Instructions for patients","Tasks to collect","IMU","EMG attachment","EMG Placement","EMG Skin","Marker attachment","Marker placement","Equipement working","Calibration","Consistency - Limits","Consistency - methods","Equipement Quality","Equipement Installation","Staff -Training","Staff - List")

UseFactor <- c("Yes","No","Not relevant for my lab")

PlotData <- SurveyData %>% select(starts_with("Q34")) %>% select(-Q34_41) %>% pivot_longer(starts_with("Q34"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[3])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928","#ba0404", "gray")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Documented?",values=mpalette) +  
          scale_color_manual(name= "Documented?",values=mpalette) 
  
ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q34_41) %>% drop_na()
doTable(TableData,col.names=c("Other Documentation"))
```

## Are your documents...? Q35 

```{r DocumentationStorage, echo=FALSE, fig.height = 4, fig.width = 7}

Questions = c("Revised after a defined period","Backed up","Available in electronic format","Stored in a folder in the lab")
ShQuestions = c("Revised after a defined period","Backed up","Available in electronic format","Stored in a folder in the lab")
UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q35")) %>% pivot_longer(starts_with("Q35"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[2])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
  scale_fill_manual(name= "Back up?",values=mpalette) +  
  scale_color_manual(name= "Back up?",values=mpalette)
  
ggpar(p,legend.title = "")

```

## Appointed auditors Q36
In order to review your documents and your practice, does your lab have appointed auditors? 

```{r DocumentationAudit, echo=FALSE, fig.height = 4, fig.width = 7}

Questions = c("Internal auditor","External auditor")
ShQuestions = c("Internal auditor","External auditor")
UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q36")) %>% pivot_longer(starts_with("Q36"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[2])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>10,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", label = FALSE, 
             lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
  scale_fill_manual(name= "Audited?",values=mpalette) +  
  scale_color_manual(name= "Audited?",values=mpalette) +
  geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

  ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")

```

# Clinical gait analysis, data acquisition

## Check equipment Q37 
Which equipment is checked before data acquisition? 

```{r DataCheck_BeforeAcquisition, echo=FALSE, , fig.height = 4, fig.width = 9}

Questions = c("EMG - crosstalk","EMG - good signal for each muscle","Forceplates offset","Presence of all stereophotogrammetric system markers","Stereophotogrammetric system Calibration quality","Digital video")
ShQuestions = c("EMG - crosstalk","EMG - good signal for each muscle","Forceplates offset","Presence of all stereophotogrammetric system markers","Stereophotogrammetric system Calibration quality","Video quality")

UseFactor <- c("Yes","No","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q37")) %>% select(-Q37_8) %>% select(-Q37_7)%>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q37"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[3])) %>% mutate(ShQuestions = replace(ShQuestions,ShQuestions == "Not relevant (because I do not use this equipment)",UseFactor[3])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Checked before?",values=mpalette) +  
          scale_color_manual(name= "Checked before?",values=mpalette)

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q37_8) %>% drop_na()
doTable(TableData,col.names=c("Other Check"))

```

## Check during acquisition Q38
What do you check during data acquisition? 

```{r DataCheck_DuringAcquisition, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("Foot placement on forceplate","Saturation of forceplate signals","Loss of forceplate signals","Noise of EMG signal (i.e. detachment of an electrode)","Loss of EMG signal","Visibility of stereophotogrammetric system markers trajectories")
ShQuestions = c("Foot placement on forceplate","Saturation of forceplate signals","Loss of forceplate signals","Noise of EMG signal","Loss of EMG signal","Visibility of markers")

UseFactor <- c("Yes","No","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q38")) %>% select(-Q38_8) %>% select(-Q38_7)%>% filter_all(any_vars(!is.na(.)))%>% pivot_longer(starts_with("Q38"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[3]))%>% mutate(ShQuestions = replace(ShQuestions,ShQuestions == "Not relevant (because I do not use this equipment)",UseFactor[3])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Checked during acquisition?",values=mpalette) +  
          scale_color_manual(name= "Checked during acquisition?",values=mpalette)


ggpar(p,legend.title = "Checked during acquisition?")

TableData <- SurveyData %>% select(Q38_8) %>% drop_na()
doTable(TableData,col.names=c("Other Check"))


```

## Check after acquisition Q39
What do you check before the patient leaves the lab? 

```{r DataCheck_BeforePatientLeaves, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("Critical loss of forceplate signals","Critical loss of EMG signal","Critical loss of markers","Number of satisfactory forceplate strikes available for kinetic analysis")
ShQuestions = c("Critical loss of forceplate signals","Critical loss of EMG signal","Critical loss of markers","Number of satisfactory forceplate strikes")

UseFactor <- c("Yes","No","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q39")) %>% select(-Q39_5) %>% select(-Q39_6)%>% filter_all(any_vars(!is.na(.)))%>% pivot_longer(starts_with("Q39"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[3]))%>% mutate(ShQuestions = replace(ShQuestions,ShQuestions == "Not relevant (because I do not use this equipment)",UseFactor[3])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")
p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Checks before patient leaving?",values=mpalette) +  
          scale_color_manual(name= "Checks before patient leaving?",values=mpalette) 

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q39_6) %>% drop_na()
doTable(TableData,col.names=c("Other Check"))


```

## Checks - other Q40
Do you perform other checks after data acquisition? 

```{r DataCheck_AfterAcquisition, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("Forceplatesignal (quality, lost of signal, number of kinetic steps)","EMG signal (quality, lost of signal, crosstalk)","Marker trajectories (quality, number of available trajectories")
ShQuestions = c("Forceplate signal","EMG signal","Marker trajectories")

UseFactor <- c("Yes","No","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q40")) %>% select(-Q40_5) %>% select(-Q40_4)%>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q40"),values_to = "ShQuestions") %>% mutate(ShQuestions = replace_na(ShQuestions,UseFactor[3]))%>% mutate(ShQuestions = replace(ShQuestions,ShQuestions == "Not relevant (because I do not use this equipment)",UseFactor[3])) %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>10,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Other checks?",values=mpalette) +  
          scale_color_manual(name= "Other checks?",values=mpalette) 

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q40_5) %>% drop_na()
doTable(TableData,col.names=c("Other Check"))

```

## Data preparation Q41
Do you do these steps for data preparation? 

```{r DataPreparation, echo=FALSE, fig.height = 4, fig.width = 10}

Questions = c("Rectification and smoothing to obtain EMG envelope","Filtering EMG signals","Smoothing forceplate signals","Smoothing marker trajectories","Gap filling marker trajectories","Event detection checked manually","Event detection performed manually","Event detection with marker trajectories (e.g. Zeni et al. 2008)","Event detection with forceplates and autocorrelation")
Guidelines = c("Rectification and smoothing to obtain EMG envelope","Filtering EMG signals","Smoothing forceplate signals","Smoothing marker trajectories","Gap filling marker trajectories","Event detection checked manually","Event detection performed manually","Event detection with marker trajectories","Event detection with forceplates and autocorrelation")

UseFactor <- c("Always","Sometimes","Never","I do not know","Not relevant")
PlotData <- SurveyData %>% select(starts_with("Q41"))%>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q41"),values_to = "Guidelines") %>% drop_na() %>% mutate(Guidelines = replace(Guidelines,Guidelines == "Device not used in my lab",UseFactor[5])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928", "#e6a01e","#0f0f0f","gray70","gray")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

```

## Event detection - Method Q42a 

```{r Event_detection, echo=FALSE, fig.height = 5, fig.width = 6}

Method <- c("I do not know","Other","Manually","Zeni","Forceplate")
WithAnswer <- c("Yes","No")

PlotData1 <- SurveyData %>% select(Q42_1a) %>% rename(Event_Method=Q42_1a) %>% mutate(Answer = ifelse(is.na(Event_Method),"No","Yes")) %>% mutate(Answer = ordered(Answer,levels=WithAnswer)) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)

PlotData2 <- SurveyData %>% select(Q42_1a) %>% rename(Event_Method=Q42_1a) %>% drop_na() %>% mutate(Event_Method = factor(Event_Method,levels=Method)) %>% group_by(Event_Method) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),""))

mpalette <- c("#1c9928","#ba0404")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "With an answer",values = mpalette) + scale_color_manual(name= "With an answer",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "left") + rremove("axis") + rremove("axis.text") + rremove("ticks")

mpalette <- c("gray90","gray70","steelblue","chartreuse3","firebrick")
p <- ggpie(PlotData2, "Freq", 
   fill = "Event_Method",label = "labs", size = 1,
   lab.pos = "in", lab.font = "white", color = "white", palette = mpalette)

p <- ggpar(p,legend = "left",legend.title = "Event detection method",tickslab = FALSE)


ggarrange(pA, p, 
          ncol = 1, nrow = 2,
          heights = c(2,6),widths = c(5,5))

TableData <- SurveyData %>% select(Q42_1b) %>% drop_na() %>% distinct()
doTable(TableData,col.names=c("Other"))

```

## Event detection - Software Q42b 

```{r Event_detectionb, echo=FALSE, fig.height = 5, fig.width = 6}

WithAnswer <- c("Yes","No")

PlotData1 <- SurveyData %>% select(Q42_2) %>% rename(Event_Method=Q42_2) %>% mutate(Answer = ifelse(is.na(Event_Method),"No","Yes")) %>% mutate(Answer = ordered(Answer,levels=WithAnswer)) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)


mpalette <- c("#1c9928","#ba0404")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "With an answer",values = mpalette) + scale_color_manual(name= "With an answer",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "left") + rremove("axis") + rremove("axis.text") + rremove("ticks")

# The actual pie chart
OrderSoftware = c("QTM","NEXUS","CODAMOTION","BTS","PYTHON","MATLAB","VISUAL3D")

mpaletteSoftware <- brewer.pal(7,"Paired")
PlotData2 <- SurveyData %>% select(Q42_2) %>% mutate(label = str_to_upper(Q42_2)) %>% select(label) %>% drop_na() %>% separate(label,into=str_c('label', seq_len(max(str_count(.$label, fixed("/")),na.rm=TRUE)+1)), sep = "\\/", fill = "right") %>% pivot_longer(everything(),names_to = "Labels",values_to = "Software") %>% mutate(Software = str_trim(Software)) %>% select(Software) %>% drop_na() %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% subset(Count > 1) %>% mutate(Software = factor(Software,levels=OrderSoftware))

p <- ggpie(PlotData2, "Freq",  fill = "Software",label = "labs",  lab.pos = "in", lab.font = "white", color = "white", palette = mpaletteSoftware)
p <- ggpar(p,legend.title = "Software",tickslab = FALSE)


ggarrange(pA, p, 
          ncol = 1, nrow = 2,
          heights = c(2,6),widths = c(5,5))


TableData <- SurveyData %>% select(Q42_2) %>% mutate(label = str_to_upper(Q42_2)) %>% select(label) %>% 
separate(label,into=str_c('label', seq_len(max(str_count(.$label, fixed("/")),na.rm=TRUE)+1)), sep = "\\/", fill = "right") %>%   pivot_longer(everything(),names_to = "Labels",values_to = "Software") %>% drop_na() %>% mutate(Software = str_trim(Software)) %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = paste0(format(Freq,digits=1),"%")) %>% subset(Count < 2)

doTable(TableData$Software,col.names = c("Other: less than 1 occurence"))

```

## Filling gaps in trajectories Q43

```{r Gap_filling, echo=FALSE, fig.height = 8, fig.width = 7}
WithAnswer <- c("No answer","I don't know","Depends","A gap size (below)")

# here with problem
PlotData1 <- SurveyData %>% select(Q43_2) %>% rename(GapSize=Q43_2) %>% replace_na(list(GapSize = "No answer")) %>% mutate(Answer = as.factor(ifelse(!is.na(as.numeric(GapSize)),"A gap size (below)",GapSize))) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)

mpalette <- c("#1c9928","grey60","grey30","#ba0404")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "With an answer",values = mpalette) + scale_color_manual(name= "With an answer",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "top") + rremove("axis") + rremove("axis.text") + rremove("ticks")

# The actual gap size graph
PlotData2 <- SurveyData %>% select(Q43_2) %>% rename(GapSize=Q43_2) %>% mutate(GapSize = as.numeric(GapSize)) %>% drop_na()

pG <- ggboxplot(PlotData2,y="GapSize",xlab = "",ylab = "",
               outlier.shape = NA) + 
      coord_flip() + 
      geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
      scale_y_continuous(breaks = c(0,5,10,20,40,60,80,100),limits = c(0,100))
pG <- ggpar(pG,title = "Gap size in number of frames",) + rremove("y.axis") + rremove("y.text") + rremove("y.ticks")

AvailableSoftware <- c(1,2,3,4,6,7)
Order <- OrderSoftware[AvailableSoftware]
mpalette <- mpaletteSoftware[AvailableSoftware]

PlotData3 <- SurveyData %>% select(Q43_3) %>% mutate(label = str_to_upper(Q43_3)) %>% select(label) %>% drop_na() %>% separate(label,into=str_c('label', seq_len(max(str_count(.$label, fixed(",")),na.rm=TRUE)+1)), sep = ",", fill = "right")%>% pivot_longer(everything(),names_to = "Labels",values_to = "Software") %>% mutate(Software = str_trim(Software)) %>% select(Software) %>% drop_na() %>% filter(Software != "I DON’T KNOW") %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% subset(Count > 1) %>% mutate(Software = factor(Software,levels=Order))

p <- ggpie(PlotData3, "Freq",  fill = "Software",label = "labs",  lab.pos = "in", lab.font = "white", color = "white", palette = mpalette)
p <- ggpar(p,title = "Software used to fill the gap (N>1)",legend.title = "",tickslab = FALSE,legend = "left")

ggarrange(pA, pG, p, 
          ncol = 1, nrow = 3,
          heights = c(1,2,3),widths = c(1,1,1))
```

## Smoothing - marker trajectories Q44

```{r Smoothing_marker_trajectories, echo=FALSE, fig.height = 8, fig.width = 8}
WithAnswer <- c("No answer","I don’t know ","Low pass filter  (Butterworth)","Woltring","Others")

# here with method
PlotData1 <- SurveyData %>% select(Q44_1) %>% rename(Answer=Q44_1) %>% replace_na(list(Answer = "No answer")) %>% mutate(Answer = ifelse(!(Answer%in%WithAnswer),"Others",Answer)) %>% mutate(Answer = ordered(Answer,levels = WithAnswer)) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)

mpalette <- c("#ba0404","grey30","forestgreen","darkolivegreen4","grey60")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "Answers: ",values = mpalette) + scale_color_manual(name= "Answers: ",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "top") + rremove("axis") + rremove("axis.text") + rremove("ticks")


# The actual gap size graph
PlotData2 <- SurveyData %>% select(Q44_1,Q44_2) %>% filter(Q44_1 == WithAnswer[3]) %>% rename(Filter=Q44_2) %>% mutate(Filter = as.numeric(Filter)) %>% drop_na()

pG <- ggboxplot(PlotData2,y="Filter",xlab = "",ylab = "Hz",outlier.shape = NA) + 
      coord_flip() + 
      geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
      scale_y_continuous(breaks = c(0,5,6,10,15,20),limits = c(0,20))
pG <- ggpar(pG,title = paste("Butterworth filter frequency when known (N = ",nrow(PlotData2),")",sep="")) + rremove("y.axis") + rremove("y.text") + rremove("y.ticks")

# The actual pie chart
AvailableSoftware <- c(1,2,3,4,6,7)
Order <- OrderSoftware[AvailableSoftware]
mpalette <- mpaletteSoftware[AvailableSoftware]

PlotData3 <- SurveyData %>% select(Q44_3) %>% mutate(label = str_to_upper(Q44_3)) %>% select(label) %>% drop_na() %>% separate(label,into=str_c('label', seq_len(max(str_count(.$label, fixed(",")),na.rm=TRUE)+1)), sep = ",", fill = "right")%>% pivot_longer(everything(),names_to = "Labels",values_to = "Software") %>% mutate(Software = str_trim(Software)) %>% select(Software) %>% drop_na() %>% filter(Software != "I DON’T KNOW") %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% subset(Count > 1) %>% mutate(Software = factor(Software,levels=Order))

p <- ggpie(PlotData3, "Freq",  fill = "Software",label = "labs",  lab.pos = "in", lab.font = "white", color = "white", palette = mpalette)
p <- ggpar(p,title = "Software used to filter (N > 1)",legend.title = "",tickslab = FALSE,legend = "left")

ggarrange(pA, pG, p, 
          ncol = 1, nrow = 3,
          heights = c(1,1,3),widths = c(1,1,1))
```

## Smoothing - forceplate signals Q45

```{r Smoothing_forceplate_signals, echo=FALSE, fig.height = 10, fig.width = 8}
WithAnswer <- c("No answer","I don’t know ","Low pass filter (Butterworth)","Woltring","No filter","Others")

# here with method
PlotData1 <- SurveyData %>% select(Q45_1) %>% rename(Answer=Q45_1) %>% replace_na(list(Answer = "No answer")) %>% mutate(Answer = ifelse(!(Answer%in%WithAnswer),"Others",Answer)) %>% mutate(Answer = ordered(Answer,levels = WithAnswer)) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)

mpalette <- c("#ba0404","grey30","forestgreen","darkolivegreen4","darkmagenta","grey60")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "Answers: ",values = mpalette) + scale_color_manual(name= "Answers: ",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "top") + rremove("axis") + rremove("axis.text") + rremove("ticks")


# The actual gap size graph
PlotData2 <- SurveyData %>% select(Q45_1,Q45_3) %>% filter(Q45_1 == WithAnswer[3]) %>% rename(Filter=Q45_3) %>% mutate(Filter = as.numeric(Filter)) %>% drop_na()

pG <- ggboxplot(PlotData2,y="Filter",xlab = "",ylab = "Hz",
               outlier.shape = NA) + 
      coord_flip() + 
      geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
      scale_y_continuous(breaks = c(0,5,10,20,50,100,250))
pG <- ggpar(pG,title = paste("Butterworth filter frequency when entered (N = ",nrow(PlotData2),")",sep="")) + rremove("y.axis") + rremove("y.text") + rremove("y.ticks")

# The actual pie chart
AvailableSoftware <- c(1,2,3,4,6,7)
Order <- OrderSoftware[AvailableSoftware]
mpalette <- mpaletteSoftware[AvailableSoftware]

PlotData3 <- SurveyData %>% select(Q45_2) %>% mutate(label = str_to_upper(Q45_2)) %>% select(label) %>% drop_na() %>% separate(label,into=str_c('label', seq_len(max(str_count(.$label, fixed(",")),na.rm=TRUE)+1)), sep = ",", fill = "right")%>% pivot_longer(everything(),names_to = "Labels",values_to = "Software") %>% mutate(Software = str_trim(Software)) %>% select(Software) %>% drop_na() %>% filter(Software != "I DON’T KNOW") %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% subset(Count > 1) %>% mutate(Software = factor(Software,levels=Order))

p <- ggpie(PlotData3, "Freq",  fill = "Software",label = "labs",  lab.pos = "in", lab.font = "white", color = "white", palette = mpalette)
p <- ggpar(p,title = "Software used to filter (N > 1)",legend.title = "",tickslab = FALSE,legend = "left")

ggarrange(pA, pG, p, 
          ncol = 1, nrow = 3,
          heights = c(2,2,3),widths = c(1,1,1))
```

## EMG - filtering Q46

```{r Filtering_EMG_signal, echo=FALSE, fig.height = 5, fig.width = 8}
WithAnswer <- c("No answer","I don’t know ","Band-pass filter","High-pass filter","Low-pass filter","No filter","Others")

# here with method
PlotData1 <- SurveyData %>% select(Q46_1) %>% rename(Answer=Q46_1) %>% replace_na(list(Answer = "No answer")) %>% mutate(Answer = ifelse(!(Answer%in%WithAnswer),"Others",Answer)) %>% mutate(Answer = ordered(Answer,levels = WithAnswer)) %>% group_by(Answer) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>5,paste0(format(Freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(Freq) - 0.5 * Freq)

mpalette <- c("#ba0404","grey30","forestgreen","darkolivegreen4","darkolivegreen2","darkmagenta","grey60")
pA <- ggbarplot(PlotData1, x=NULL,"Freq", fill = "Answer",color = "Answer",
  orientation = "horiz",xlab = "", ylab = "", position = position_stack(reverse=TRUE)) +
  scale_fill_manual(name= "Answers: ",values = mpalette) + scale_color_manual(name= "Answers: ",values = mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Answer"),
    color = "white"
  )
pA <- ggpar(pA,legend = "top") + rremove("axis") + rremove("axis.text") + rremove("ticks")

# The actual gap size graph
FreqName = c("low","high")
PlotData2 <- SurveyData %>% select(Q46_1,Q46_2) %>% filter(Q46_1 == WithAnswer[3] & Q46_2 != "I don’t know ") %>% rename(Filter=Q46_2) %>% drop_na() %>% separate(Filter,into=str_c('Freq', seq_len(max(str_count(.$Filter, fixed("-")),na.rm=TRUE)+1)), sep = "-", fill = "right")%>% mutate(Low = as.numeric(Freq1),High = as.numeric(Freq2)) %>% select(Low,High) %>% pivot_longer(everything(),names_to = "Frequency",values_to = "Value")

pG1 <- ggboxplot(PlotData2%>%filter(Frequency=="Low"),x="Frequency",y="Value",xlab="",ylab ="Hz",
               outlier.shape = NA) + 
      coord_flip() + 
      geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
      scale_y_continuous(limits = c(0,40)) 
pG1 <- ggpar(pG1) + rremove("y.axis") + rremove("y.ticks")
pG2 <- ggboxplot(PlotData2%>%filter(Frequency=="High"),x="Frequency",y="Value",xlab="",ylab ="Hz",
               outlier.shape = NA) + 
      coord_flip() + 
      geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1)) + 
      scale_y_continuous(limits = c(200,800)) 
pG2 <- ggpar(pG2)+ rremove("y.axis") + rremove("y.ticks")
pG <- ggarrange(pG1, pG2, ncol = 2, nrow = 1, heights = c(1,1),widths = c(1,1))
pG <- annotate_figure(pG, fig.lab = paste("Band-pass frequencies when entered (N = ",nrow(PlotData2),")",sep=""),fig.lab.pos="top.left")

ggarrange(pA, pG,
          ncol = 1, nrow = 2,
          heights = c(1,2),widths = c(1,1))
```

## EMG - software Q47
Software to process EMG (filtering, rectification, and smoothing)

```{r Rect_smooth_EMG, echo=FALSE, fig.height = 6, fig.width = 8}
# The actual pie chart
AvailableSoftware <- c(1,2,4,5,6,7,8,9,10,11)
Order <- c("QTM","NEXUS","BTS","PYTHON","MATLAB","VISUAL3D","NORAXON","PROEMG","EMGWORKS","EMG EASY REPORT")
mpalette <- brewer.pal(11,"Paired")
mpalette <- mpalette[AvailableSoftware]
mpalette[10]<- "grey30"
PlotData <- SurveyData %>% select(Q46_3,Q47_2) %>% pivot_longer(everything(),names_to = "Question", values_to = "Software") %>% separate(Software,into=str_c('Software', seq_len(max(str_count(.$Software, fixed(",")),na.rm=TRUE)+1)), sep = ",", fill = "right") %>% pivot_longer(starts_with("Software"),names_to = "Item",values_to = "Software")%>% mutate(Software = str_trim(Software)) %>% drop_na() %>% select(Software) %>% mutate(Software = str_to_upper(Software)) %>% filter(Software != "I DON’T KNOW") %>% group_by(Software) %>% summarise(Count = n()) %>% mutate(Freq = 100 * Count/sum(Count)) %>% mutate(labs = ifelse(Freq>3,paste0(format(Freq,digits=1),"%"),"")) %>% subset(Count > 2) %>% mutate(Software = factor(Software,levels=Order)) %>%  arrange(Software)

p <- ggpie(PlotData, "Freq",  fill = "Software",label = "labs",  lab.pos = "in", lab.font = "white", color = "white", palette = mpalette)
p <- ggpar(p,title = "Software to process EMG (filtering, rectification, and smoothing)",legend.title = "",tickslab = FALSE,legend = "left")
p
```

# Clinical gait analysis, data processing

## Customisation of gait model Q48
For kinematics and kinetics computation, do you use the Conventional Gait Model (i.e. Plug-in-Gait) without any customisation? 

```{r CGM, echo=FALSE, fig.height = 4, fig.width = 8}

Questions = c("For kinematics  and kinetics computation, do you use the Conventional Gait Model?")
Guidelines = c("Do you use the CGM?")
UseFactor <- c("Always","Sometimes","I do not know","Never","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q49a_1")) %>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q49a_1"),values_to = "Guidelines") %>% separate(name,c("Q","num"),sep="_") %>% mutate(Guidelines = replace(Guidelines,Guidelines == "Device not used in my lab",UseFactor[5])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "gray60", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"),color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")
```

## CGM, wands or markers? Q49b
If you use the CGM, do you use wands or markers for thigh and shank?  

```{r CGM - Markers or wands, echo=FALSE, fig.height = 4, fig.width = 7}
Questions = c("if you use the CGM, do you use wands or markers for thigh and shank?")
Guidelines = c("Markers or Wands?")
UseFactor <- c("Wands","Markers")

PlotData <- SurveyData %>% select(starts_with("Q49b_1")) %>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q49b_1"),values_to = "Guidelines") %>% separate(name,c("Q","num"),sep="_") %>% mutate(Guidelines = replace(Guidelines,Guidelines == "Device not used in my lab",UseFactor[5])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>10,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "CGM with",values=mpalette) + 
          scale_color_manual(name= "CGM with",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")
```

## CGM, KAD? Q49c
If you use the CGM, do you use the KAD?  

```{r CGM - KAD, echo=FALSE, fig.height = 4, fig.width = 7}
Questions = c("if you use the CGM, do you use the KAD?")
Guidelines = c("KAD or Without KAD?")
UseFactor <- c("KAD","Without KA")

PlotData <- SurveyData %>% select(starts_with("Q49c_1")) %>% filter_all(any_vars(!is.na(.))) %>% pivot_longer(starts_with("Q49c_1"),values_to = "Guidelines") %>% separate(name,c("Q","num"),sep="_") %>% mutate(Guidelines = replace(Guidelines,Guidelines == "Device not used in my lab",UseFactor[2])) %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>10,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")
```

## Models used Q50a
Modified analysis - Most used model for kinematics and kinetics? 

```{r Most used model, echo=FALSE, fig.height = 4, fig.width = 9}

Guidelines= c("Gait model mostly used")
UseFactor <- c("CGM standard","CGM custom","CAST","HBM","IOR Gait","I do not know","Device not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q50a")) %>% pivot_longer(starts_with("Q50a"),values_to = "Guidelines") %>% drop_na() %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)


mpalette <- c("#3BA500","#9ED10F","#DD3730","#2476FF","#B07ACB","#979797","#3B3B3B")
p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "Guidelines",values=mpalette) + 
          scale_color_manual(name= "Guidelines",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")

```

## Hip joint center estimation Q51
Please specify the method to determine hip joint center?  

```{r Hip joint center method, echo=FALSE, fig.height = 4, fig.width = 9}

Questions = c("Please specify the method to determine hip joint center")
Guidelines_complete = c("Predictive method (e.g. Bell 1990, Davis 1991, Harrington 2007,  Hara 2016 )","Functional calibration with specific movements (e.g. circumduction)","Functional calibration using gait trials","Ultrasound imaging","Other imaging techniques","Please specify reference of the method or other method (e.g. Predictive: Hara et al 2016)")
Guidelines= rev(c("Predictive methods","Functional calibration (movements)","Functional calibration (gait trials)","Ultrasound imaging","Other imaging techniques")) # instead of reverting in Excel I revert the data here
UseFactor <- c("Always","Sometimes", "Never", "I don't know")

PlotData <- SurveyData %>% select(starts_with("Q51"))  %>% select(-Q51_6) %>% pivot_longer(starts_with("Q51"),values_to = "Guidelines")  %>% drop_na() %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines",
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q51_6) %>% drop_na()
doTable(TableData,col.names=c("Hip joint center method determination used"))
```

## Knee joint center/axis Q52
Please specify the method to determine knee joint center/axis?   

```{r knee joint center/axis method, echo=FALSE, fig.height = 4, fig.width = 9}
Guidelines_complete = c("Predictive method","Mid-distance between epicondyles","Chord function (Conventional Gait Model)","Knee Alignment Device (KAD)","Functional calibration with specific movements (e.g. squatting)","Functional calibration using gait trials (e.g. axis correction)","Ultrasound imaging","Please specify reference of the method or other method")
Guidelines= rev(c("Predictive method","Mid-distance epicondyles","Chord function (Conventional Gait Model)","Knee Alignment Device (KAD)","Functional calibration (movements)","Functional calibration (gait trials)","Ultrasound imaging")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Always","Sometimes", "Never", "I don't know")

PlotData <- SurveyData %>% select(starts_with("Q52"))  %>% select(-Q52_8) %>% pivot_longer(starts_with("Q52"),values_to = "Guidelines")  %>% drop_na() %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "Guidelines", color = "Guidelines", 
             label = NULL, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Guidelines) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q52_8) %>% drop_na()
doTable(TableData,col.names=c("Knee joint center method determination used"))
```

## Ankle joint center/axis Q53
Please specify the method to determine ankle joint center/axis?  

```{r ankle joint center/axis method, echo=FALSE, fig.height = 4, fig.width = 10}

Methods_complete = c("Predictive method","Mid-distance between malleoli","Chord function (Conventional Gait Model)","Functional calibration with specific movements","Functional calibration using gait trials","Ultrasound imaging","Other imaging techniques","Please specify reference of the method or other method")
Methods= rev(c("Predictive method","Mid-distance malleoli","Chord function (Conventional Gait Model)","Functional calibration (movements)","Functional calibration (gait trials)","Ultrasound imaging","Other imaging techniques")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Always","Sometimes", "Never", "I don't know")

PlotData <- SurveyData %>% select(starts_with("Q53"))  %>% select(-Q53_8) %>% pivot_longer(starts_with("Q53"),values_to = "Methods")  %>% drop_na() %>% mutate(Methods = factor(Methods,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Methods) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Methods", color = "Methods", label = NULL, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Methods) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q53_8) %>% drop_na()
doTable(TableData,col.names=c("Ankle joint center method determination used"))
```

## Inertial parameters Q54
Please specify the method to determine body segment inertial parameters?  

```{r body segment inertial parameters , echo=FALSE, fig.height = 4, fig.width = 10}

Methods_complete = c("From tables (e.g. Dempster, Zatsiorsky)","Measured")
Methods= rev(c("From tables (e.g. Dempster, Zatsiorsky)","Measured")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Always","Sometimes", "Never", "I don't know", "Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q54"))  %>% select(-Q54_3) %>% pivot_longer(starts_with("Q54"),values_to = "Methods")  %>% drop_na() %>% mutate(Methods = factor(Methods,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Methods) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70", "gray80")

p<-ggbarplot(PlotData, "name", "freq", fill = "Methods", color = "Methods", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Methods) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")

TableData <- SurveyData %>% select(Q54_3) %>% drop_na()
doTable(TableData,col.names=c("Method to determine body segment inertial parameters used"))
```

## EMG computation Q55
Which methods do you use for EMG computation?  

```{r EMG methods, echo=FALSE, fig.height = 4, fig.width = 12}
# I removed the %>% mutate(Guidelines = replace_na(Guidelines,UseFactor[1]))
# i added %>% drop_na()
#OK
Guidelines_complete = c("Onset are detected (always, sometimes, never, I don’t know)","EMG envelopes are normalised by a the maximum during the task","EMG envelopes are normalised by a specific task","EMG envelopes are normalised by submaximal voluntary contraction","EMG envelopes are normalised by maximal voluntary contraction")
Guidelines= c("Onset detected","EMG envelopes normalised maximum during the task","EMG envelopes  normalised by  specific task","EMG envelopes normalised by submaximal voluntary contraction","EMG envelopes normalised by maximal voluntary contraction")
UseFactor <- c("Always","Sometimes","I do not know","Never","Device not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q55"))  %>% select(-Q55_6) %>% pivot_longer(starts_with("Q55"),values_to = "Guidelines") %>% drop_na() %>% mutate(Guidelines = factor(Guidelines,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Guidelines) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70", "gray80")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Guidelines", color = "Guidelines", label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=Guidelines) + scale_fill_manual(name= "",values=mpalette) + scale_color_manual(name= "",values=mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "")
TableData <- SurveyData %>% select(Q55_6) %>% drop_na()
doTable(TableData,col.names=c("EMG method specification used"))
```

## Reported methods Q56
Which methods used for data preparation and computation do you report in the technical report?  

```{r Methods Data Preparation, echo=FALSE, fig.height = 4, fig.width = 9}

Methods_complete = c("Event detection","Marker trajectories - gap filling","Marker trajectories - smoothing","Forceplate - smoothing","EMG - filtering","EMG - rectification and smoothing","EMG - normalization","Spatiotemporal normalization","Kinematic computations","Kinetic computations","Other","if Other, please specify")
Methods= rev(c("Event detection","Marker trajectories - gap filling","Marker trajectories - smoothing","Forceplate - smoothing","EMG - filtering","EMG - rectification and smoothing","EMG - normalization","Spatiotemporal normalization","Kinematic computations","Kinetic computations", "Other")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Yes","No", "Device not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q56"))  %>% select(-Q56_12) %>% pivot_longer(starts_with("Q56"),values_to = "Methods")  %>% drop_na() %>% mutate(Methods = factor(Methods,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Methods) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- get_palette(c("#1c9928", "#ba0404", "gray"), 3)

p<-ggbarplot(PlotData, "name", "freq", fill = "Methods", color = "Methods", label = PlotData$labs, 
             lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Methods) +
          scale_fill_manual(name= "",values=mpalette) +
          scale_color_manual(name= "",values=mpalette) 

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q56_12) %>% drop_na()
doTable(TableData,col.names=c("Methods for data preparation and computation report in technical report"))

```

## Recommendations and standards Q57
Does the data presented in the report follow the following recommendations/standards?  

```{r Reported Data in line with Recommendations, echo=FALSE, fig.height = 4, fig.width = 8}
Recommendations_complete = c("ISB recommendations for kinematics (Wu et al., 1995, 2002, 2005)","ISB recommendations for kinetics (Derrick et al., 2019)","ISEK Standards for Reporting EMG Data","Other standards","if Other, please specify")
Recommendations= rev(c("ISB recommendations (kinematics)","ISB recommendations (kinetics)","ISEK Standards (EMG)", "Other standards")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Completely","Partially", "Device not used in my lab", "I don't know")

PlotData <- SurveyData %>% select(starts_with("Q57"))  %>% select(-Q57_5) %>% pivot_longer(starts_with("Q57"),values_to = "Recommendations")  %>% drop_na() %>% mutate(Recommendations = factor(Recommendations,levels=UseFactor)) %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Recommendations) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e", "black","gray70")

p<-ggbarplot(PlotData, "name", "freq", fill = "Recommendations", color = "Recommendations", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Recommendations) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")
TableData <- SurveyData %>% select(Q57_5) %>% drop_na()
doTable(TableData,col.names=c("Data presented in the report follow recommendations/standards"))

```

## Upper body Q58
During CGA, do you perform the kinematics acquisition of the following body parts'on top of the lower limb and pelvis?  

```{r Kinematics of Body Parts, echo=FALSE, fig.height = 4, fig.width = 8}
Parts_complete = c("Trunk","Spine","Head","Arms","Hands","Foot (multi-segments)","Other, please specify")
Parts= rev(c("Trunk","Spine","Head","Arms","Hands","Foot (multi-segments)","Other")) # instead of reverting in Excel I revert the data here

UseFactor <- c("Always","Sometimes","Never", "I do not know", "Device not used in my lab")

PlotData <- SurveyData %>% select(starts_with("Q58"))  %>% select(-Q58_7) %>% pivot_longer(starts_with("Q58"),values_to = "Parts")  %>% drop_na() %>% mutate(Parts = factor(Parts,levels=UseFactor)) %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Parts) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#e6a01e","black")

p<-ggbarplot(PlotData, "name", "freq", fill = "Parts", color = "Parts", label = FALSE, 
             lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Parts) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")
TableData <- SurveyData %>% select(Q58_7) %>% drop_na()
doTable(TableData,col.names=c("Kinematic acquisition of body parts'on top lower limb and pelvis"))
```

## Software biomechanical computation Q59
Which software do you use for any of the biomechanical computation?  

```{r Software for computation, echo=FALSE, fig.height = 4, fig.width = 8}
Respondent <- SurveyData %>% select(starts_with("Q59")) %>% select(-Q59_11) %>% mutate(test = rowSums(is.na(.))/ncol(.)) %>% summarise(n = sum(.$test != 1))
SoftwareName <- LabelData %>% filter(Q=="Q59")%>%select(num,ShortAnswers)%>%filter(num!=12) %>% mutate(name = num) %>% select(-num)

PlotData <- SurveyData %>% select(starts_with("Q59"))  %>% select(-Q59_12) %>% pivot_longer(starts_with("Q59"),values_to = "SoftwareLong") %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% drop_na() %>% merge(SoftwareName) %>% group_by(name,ShortAnswers)  %>% summarise(n = n())  %>% mutate(freq = 100 * n / Respondent$n) %>% mutate(labs = ifelse(freq>3,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(freq))

mpalette <- get_palette("lancet",11)
p<-ggbarplot(PlotData, "ShortAnswers", "freq", fill = "ShortAnswers", color = "ShortAnswers", palette=mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "", legend = "none")

TableData <- SurveyData %>% select(Q59_12) %>% drop_na()
doTable(TableData,col.names=c("Software used for biomechanical computation"))
```

## Advanced methodologies Q60 
Do you use any of the below methodologies as part of your CGA and how often?  

```{r Methods used during CGA, echo=FALSE, fig.height = 5, fig.width = 10}
Methodology = rev(c("OpenSim / Biomechanical modelling","EMG analytics like muscle synergies","Automated clinical reasoning","Video-based human pose estimation software (such as OpenPose)","Machine learning algorithms (such as DeepEvent)","Other","Please specify")) # instead of reverting in Excel I revert the data here
MethodologySh = rev(c("Modelling (e.g. OpenSim)","EMG analytics (e.g. muscle synergies)","Automated clinical reasoning","Video-based pose estimation (e.g. OpenPose)","Machine learning (e.g. DeepEvent)"))

UseFactor <- c("Always", "Often", "Regularly", "Sometimes","Never")

PlotData <- SurveyData %>% select(starts_with("Q60"))  %>% select(-Q60_7, -Q60_6) %>% pivot_longer(starts_with("Q60"),values_to = "Methodology") %>% drop_na() %>% mutate(Methodology = factor(Methodology,levels=UseFactor)) %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Methodology) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#81A814", "#e6a01e", "#FFC500", "black")

p<-ggbarplot(PlotData, "name", "freq", fill = "Methodology", color = "Methodology", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=MethodologySh) + 
          scale_fill_manual(name= "",values=mpalette) + 
          scale_color_manual(name= "",values=mpalette) +
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q60_7) %>% drop_na()
doTable(TableData,col.names=c("Methodologies used as part of CGA and how often"))
```

# Clinical gait analysis, data reporting

## Software reporting Q61
Which software do you use to prepare the technical report? 

```{r Software Technical Report, echo=FALSE, fig.height = 4, fig.width = 8}
Respondent <- SurveyData %>% select(starts_with("Q61")) %>% select(-Q61_9) %>% mutate(test = rowSums(is.na(.))/ncol(.)) %>% summarise(n = sum(.$test != 1))
SoftwareName <- LabelData %>% filter(Q=="Q61") %>% select(num,ShortAnswers) %>% filter(num!=12) %>% mutate(name = num) %>% select(-num)

PlotData <- SurveyData %>% select(starts_with("Q61"))  %>% select(-Q61_2,-Q61_3,-Q61_9) %>% pivot_longer(starts_with("Q61"),values_to = "SoftwareLong") %>%  separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% drop_na() %>% merge(SoftwareName) %>% group_by(name,ShortAnswers)  %>% summarise(n = n())  %>% mutate(freq = 100 * n / Respondent$n) %>% mutate(labs = ifelse(freq>2,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(freq))

mpalette <- get_palette("lancet",11)
p<-ggbarplot(PlotData, "ShortAnswers", "freq", fill = "ShortAnswers", color = "ShortAnswers", palette=mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1,
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "", legend = "none")


```

## CGA reporting - content Q62
What does your CGA report include?  

```{r CGA report, echo=FALSE, fig.height = 4, fig.width = 8}
Questions = rev(c("Technical report with data collected during CGA (graphs, …)","Medical report with interpretation of the technical report","Multimedia report including video"))

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q62")) %>% pivot_longer(starts_with("Q62"), values_to = "Questions") %>% drop_na() %>% mutate(Questions = factor(Questions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Questions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "Questions", color = "Questions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Questions) + 
          scale_fill_manual(name= "",values=mpalette) +  
          scale_color_manual(name= "",values=mpalette)

ggpar(p,legend.title = "")

```

## CGA reporting - information Q63
Does your report include the following information?  

```{r CGA Report Info Included, echo=FALSE, fig.height = 5, fig.width = 10}
Questions = rev(c("Name and date of birth of the patient on each page","Identification of chief complaint or reason for study","Comprehensive clinical history","Documentation of past and current treatment","Description of the clinical exam","A consideration of the consistency of the patient’s gait pattern, supported by data","Conditions under which data were collected (e.g. barefoot)","Patient compliance/co-operation","Comments on whether data are typical for the patient","Any problems or artefacts identified","Any corrections applied during data collection and processing","Functional diagnosis","Identification of Clinically Important Deviations/Abnormalities","Therapeutic recommendations","Staff member(s) responsible for the data acquisition","Staff member(s) responsible for the therapeutic recommendations","Signature of the staff/ designated signatory for lab","Other","Please specify"))

ShQuestions = rev(c("Name/birth on each page","Reason for study","Comprehensive clinical history","Documentation of treatment","Description clinical exam","Consideration gait pattern consistency","Conditions data collection","Patient compliance/co-operation","Comments on data","Any problems or artefacts identified","Data corrections applied","Functional diagnosis","Clinically Important Deviations/Abnormalities","Therapeutic recommendations","Staff member(s) acquisition","Staff member(s) therapeutic recommendations","Signature","Other"))

UseFactor <- c("Yes","No","Not relevant")

PlotData <- SurveyData %>% select(starts_with("Q63")) %>% select(-Q63_19) %>% pivot_longer(starts_with("Q63"),values_to = "ShQuestions") %>% drop_na() %>% mutate(ShQuestions = factor(ShQuestions,levels=UseFactor))  %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,ShQuestions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404")

p<-ggbarplot(PlotData, "name", "freq", fill = "ShQuestions", color = "ShQuestions", 
             label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=ShQuestions) + 
          scale_fill_manual(name= "Documented?",values=mpalette) +  
          scale_color_manual(name= "Documented?",values=mpalette) 

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q63_19) %>% drop_na()
doTable(TableData,col.names=c("Other Documentation"))
```

## CGA reporting - visualization Q64
Does your report display the following data?  

```{r Report Data, echo=FALSE, fig.height = 11, fig.width = 9}
NameData <- LabelData %>% filter(Q=="Q64")%>%select(num,ShortAnswers)

UseFactor <- c("Always","Sometimes", "Never")

PlotData <- SurveyData %>% select(starts_with("Q64"))  %>% select(-Q64_45,-Q64_44) %>% pivot_longer(starts_with("Q64"),values_to = "Agree")  %>% drop_na() %>% mutate(Agree = factor(Agree,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0")) %>% merge(NameData) %>% group_by(ShortAnswers,num,Agree) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(num))

mpalette <- c("#1C9928", "#FFC500", "black")

p<-ggbarplot(PlotData, "ShortAnswers", "freq", fill = "Agree", color = "Agree", palette = mpalette,
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q64_45) %>% drop_na()
doTable(TableData,col.names=c("Other data reported"))
```

## CGA reporting - normative values Q65
If you report normative values these are   

```{r Q65, echo=FALSE, fig.height = 4, fig.width = 7.5}

NameData <- LabelData %>% filter(Q=="Q65")%>%select(num,ShortAnswers)

FullData <- SurveyData %>% select(starts_with("Q65")) %>% mutate(isData = ifelse(rowSums(is.na(.))<length(.),1,0))
Ndata <- sum(FullData$isData)

PlotData <- FullData %>% filter(isData == 1) %>% select(-isData) %>% pivot_longer(starts_with("Q65"),values_to = "DataReported") %>%  separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0")) %>% drop_na() %>% group_by(num,DataReported) %>% summarise(n = n()) %>% mutate(freq = 100 * n / Ndata) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% arrange(desc(freq))

mpalette <- get_palette("lancet",6)
p<-ggbarplot(PlotData, "DataReported", "freq", palette = mpalette,
  fill = "DataReported", color = "DataReported", label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))


ggpar(p,legend.title = "", legend = "none")

```

## Normative data - check Q66
Do you check your normal data against literature?  

```{r Q66, echo=FALSE, fig.height = 4, fig.width = 8.5}
Answer = "Do you check your normal data against literature?"
UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q66"))%>% select(-Q66_2) %>% pivot_longer(starts_with("Q66"), values_to = "Answer") %>% drop_na() %>% mutate(Answer = factor(Answer,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Answer) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")
p<-ggbarplot(PlotData, "name", "freq", fill = "Answer", color = "Answer", 
             label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
             orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

p <- p  + scale_x_discrete(labels=Answer) + 
          scale_fill_manual(name= "",values=mpalette) +  
          scale_color_manual(name= "",values=mpalette) + 
          geom_text(aes(y = lab_ypos, label = labs, group = "Type"), color = "white")

ggpar(p,legend.title = "") + rremove("axis") + rremove("ticks") + rremove("x.text") + rremove("xlab")

TableData <- SurveyData %>% select(Q66_2) %>% drop_na()
doTable(TableData,col.names=c("Norm data references used"))

```

## Normative data - amount Q67 
How many subjects are included in total in the normative database? 

```{r Q67, echo=FALSE, fig.height = 4, fig.width = 7}

PlotData <- SurveyData %>% select(starts_with("Q67")) %>% 
pivot_longer(starts_with("Q67"),values_to = "N") %>% drop_na() %>% filter(N>0)

p <- ggviolin(PlotData,x="name",y="N", ylab = "", 
              xlab = "N of normative dataset ", fill = "name",
              trim = TRUE, draw_quantiles = 0.5,outlier.shape = NA) +
    scale_x_discrete(labels="") +
    scale_y_continuous(breaks = c(0,20,40,60,80,100),limits = c(0,100))

ggpar(p,legend = "none", title = paste("Number of subjects in normative database, from ",nrow(PlotData)," respondents",sep = "")) +
geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1))

```

## Identify gait deviations Q68
How do you identify gait deviations on the graphs of the report?   

```{r Q68, echo=FALSE, fig.height = 4, fig.width = 7}
Questions = rev(c("Baker convention (Baker, Measuring walking - a Handbook of Clinical Gait Analysis)","Comprehensive description","Other"))
QuestionsSh = rev(c("Baker convention","Comprehensive description","Other"))

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q68")) %>% select(-Q68_4) %>% pivot_longer(starts_with("Q68"), values_to = "Questions") %>% drop_na() %>% mutate(Questions = factor(Questions,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Questions) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1c9928","#ba0404", "gray")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Questions", color = "Questions", palette = mpalette,
  label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=QuestionsSh)

ggpar(p,legend.title = "")

TableData <- SurveyData %>% select(Q68_4) %>% drop_na()
doTable(TableData,col.names=c("Others methods to identify gait deviations"))
```

## CGA reporting - to whom Q69
To whom is your CGA report delivered?  

```{r Q69, echo=FALSE, fig.height = 4, fig.width = 6}
Receiver = rev(c("To the referring professional","To the patient","Other"))

UseFactor <- c("Always","Sometimes", "Never")

PlotData <- SurveyData %>% select(starts_with("Q69"))  %>% select(-Q69_4) %>% pivot_longer(starts_with("Q69"),values_to = "Receiver")  %>% drop_na() %>% mutate(Receiver = factor(Receiver,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Receiver) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>5,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#FFC500", "black")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Receiver", color = "Receiver", label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=Receiver) + scale_fill_manual(name= "",values=mpalette) + scale_color_manual(name= "",values=mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "")
TableData <- SurveyData %>% select(Q69_4) %>% drop_na()
doTable(TableData,col.names=c("Other data reported"))
```

## Data for decision making Q70
Which clinical data do you use in combination with 3D GA for decision making or follow up assessments?  

```{r Q70, echo=FALSE, fig.height = 4, fig.width = 8}
Data = rev(c("Specific functional standardized tools","ROM assessment","Strength assessment","Selective motor control assessment","Spasticity assessment","Morphological deformities measurements","Neurological examination","Medical imaging","Medical history","Other"))

UseFactor <- c("Always","Sometimes", "Never")

PlotData <- SurveyData %>% select(starts_with("Q70"))  %>% select(-Q70_11) %>% pivot_longer(starts_with("Q70"),values_to = "Data")  %>% drop_na() %>% mutate(Data = factor(Data,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(name = str_pad(num, 2, pad = "0")) %>% group_by(name,Data) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq)

PlotData <- PlotData %>% arrange(desc(as.numeric(name)))

mpalette <- c("#1C9928", "#FFC500", "black")
p<-ggbarplot(PlotData, "name", "freq",
  fill = "Data", color = "Data", label = FALSE, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))
p <- p  + scale_x_discrete(labels=Data) + scale_fill_manual(name= "",values=mpalette) + scale_color_manual(name= "",values=mpalette) +
  geom_text(
    aes(y = lab_ypos, label = labs, group = "Type"),
    color = "white"
  )
ggpar(p,legend.title = "")
TableData <- SurveyData %>% select(Q70_11) %>% drop_na()
doTable(TableData,col.names=c("Other data reported"))

```

## Information to patients Q71
What information do you provide for the patients?  

```{r Q71, echo=FALSE, fig.height = 3, fig.width = 10}
NameData <- LabelData %>% filter(Q=="Q71")%>%select(num,Answers)

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q71")) %>% pivot_longer(starts_with("Q71"),values_to = "Information")  %>% drop_na() %>% mutate(Information = factor(Information,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0"))%>% merge(NameData)%>% group_by(Answers,num,Information) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(num))

mpalette <- get_palette(c("#1c9928", "#ba0404", "gray"), 3)
p<-ggbarplot(PlotData, "Answers", "freq",
  fill = "Information", color = "Information", palette = mpalette,
  label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "What information do you provide to the patient?")
```

## Storage - raw data Q72
CGA raw data are stored?  

```{r Q72, echo=FALSE, fig.height = 4, fig.width = 8.5}
NameData <- LabelData %>% filter(Q=="Q72")%>%select(num,Answers)

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q72")) %>% pivot_longer(starts_with("Q72"),values_to = "Information")  %>% drop_na() %>% mutate(Information = factor(Information,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0"))%>% merge(NameData)%>% group_by(Answers,num,Information) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(num))

mpalette <- get_palette(c("#1c9928", "#ba0404", "gray"), 3)
p<-ggbarplot(PlotData, "Answers", "freq",
  fill = "Information", color = "Information", palette = mpalette,
  label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "Where are raw data stored?")

```

## Storage - processed data Q73
CGA processed data are stored?  

```{r Q73, echo=FALSE, fig.height = 4, fig.width = 8.5}
NameData <- LabelData %>% filter(Q=="Q73")%>%select(num,Answers)

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q73")) %>% pivot_longer(starts_with("Q73"),values_to = "Information")  %>% drop_na() %>% mutate(Information = factor(Information,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0"))%>% merge(NameData)%>% group_by(Answers,num,Information) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(num))

mpalette <- get_palette(c("#1c9928", "#ba0404", "gray"), 3)
p<-ggbarplot(PlotData, "Answers", "freq",
  fill = "Information", color = "Information", palette = mpalette,
  label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "Where are processed data stored?")
```

## Storage - report Q74
CGA reports are stored  

```{r Q74, echo=FALSE, fig.height = 4, fig.width = 8.5}
NameData <- LabelData %>% filter(Q=="Q74")%>%select(num,Answers)

UseFactor <- c("Yes","No")

PlotData <- SurveyData %>% select(starts_with("Q74")) %>% pivot_longer(starts_with("Q74"),values_to = "Information")  %>% drop_na() %>% mutate(Information = factor(Information,levels=UseFactor)) %>% separate(name,c("Q","num"),sep="_") %>% mutate(num = str_pad(num, 2, pad = "0"))%>% merge(NameData)%>% group_by(Answers,num,Information) %>% summarise(n = n()) %>% mutate(freq = 100 * n / sum(n)) %>% mutate(labs = ifelse(freq>1,paste0(format(freq,digits=1),"%"),"")) %>% mutate(lab_ypos = cumsum(freq) - 0.5 * freq) %>% arrange(desc(num))

mpalette <- get_palette(c("#1c9928", "#ba0404", "gray"), 3)
p<-ggbarplot(PlotData, "Answers", "freq",
  fill = "Information", color = "Information", palette = mpalette,
  label = PlotData$labs, lab.col = "white", lab.vjust = 0.5, lab.hjust = 1, 
  orientation = "horiz",xlab = "", ylab = "%", position = position_stack(reverse=TRUE))

ggpar(p,legend.title = "Where are CGA reports stored?")
```

## Storage - duration Q75
What is the duration of the storage? Please enter a number of years.  

```{r Q75, echo=FALSE, fig.height = 4, fig.width = 7}
DataLabel <- c("Raw data","Processed data","Reports")

PlotData <- SurveyData %>% select(starts_with("Q75")) %>% mutate(across(everything(),as.numeric)) %>% 
pivot_longer(starts_with("Q75"),values_to = "Duration") %>% drop_na()

PlotData[PlotData==999] <- NA

p <- ggboxplot(PlotData,x="name",y="Duration", fill = "name",xlab = "", ylab = "Duration (years)", outlier.shape = NA) +
    scale_x_discrete(labels=DataLabel) +
    coord_flip()

ggpar(p,legend = "none") +
geom_point(size = 1.5, alpha = 0.25, position = position_jitter(width = 0.2, height = 0, seed = 1))

```
