-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepresentativeData.R
More file actions
150 lines (119 loc) · 5.94 KB
/
representativeData.R
File metadata and controls
150 lines (119 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#Purpose: Plot the EMP sample data in comparison to the pubmed data
#Project: EEGManyPipes
#Paper: Trübutschek, D. et al. EEGManyPipelines: A large-scale, grass-root multi-analyst study of EEG analysis practices in the wild. (2022). doi:10.31222/osf.io/jq342
#Author: D. Truebutschek, M. C. Vinding, & Y. Yang
#Date: 04-10-2022
################################################################################
#Necessary imports
library(tidyverse)
library(optimbase)
library(ggthemes)
library(wesanderson)
library(RColorBrewer)
library(svglite)
library(forcats)
################################################################################
#Path definitions
if ( Sys.getenv("USER") == 'mcvinding' ){
data.path <- '/Users/mcvinding/Documents/EEGManyPipelines/metadata_summary'
} else if (Sys.getenv("USERNAME") == 'Mikkel'){
data.path <- 'C:/Users/Mikkel/Documents/EEGManyPipelines/metadata_summary'
} else if (Sys.getenv("USER") == 'darinka'){
data.path <- '/home/darinka/Documents/EEGManyPipes/metadata_summary/data'
} else if (Sys.getenv("USERNAME") == 'darinka.truebutschek'){
data.path <- 'C:/Users/darinka.truebutschek/Documents/EEGManyPipelines/metadata_summary/data'
} else {
# Paths and file for Yu-Fang
rm(list=ls())
path= dirname(rstudioapi::getActiveDocumentContext()$path)
setwd(path)
getwd()
data <- read.csv("final_data.csv")
}
setwd(data.path)
################################################################################
#Load data
data <- read.csv("percent_countries_pubmed_emp_figure_checkedDT.csv")
################################################################################
#Plot data - vertical
my_colors = c('#69A19C', '#A9A9A9')
my_alphas = c(1, 1, 1, 1)
theme_set(theme_classic())
g <- ggplot(data, aes(fill=fill, x=continents, y=count, widths=.8)) +
geom_bar(stat='identity', position=position_dodge(.8)) +
#Add percentage labels to the individual bars
geom_text(aes(x=continents, y=count, label=paste0(sprintf("%4.0f", round(count, digits=0)), '%'),
group=fill), vjust=-0.5,
position=position_dodge(.8),
family='sans', size=3.5, fontface='bold', color='dimgray') +
#Adjust colors
scale_fill_manual(values=my_colors, labels=c('Analysts', 'Pubmed authors')) +
#Adjust legend
theme(legend.title=element_text(size=12, color='dimgray', face='bold'),
legend.position=c(.2,.8),
legend.text=element_text(size=12, color='dimgray')) +
#Change axis labels
labs(x=' ', y='Percent', fill='Sample') +
#Change the aspect ratio of the plot
#theme(aspect.ratio=.7) +
#Remove unnecessary white space between axis and bars
scale_x_discrete(expand=c(0,0)) +
scale_y_continuous(limits=c(0, 73), expand=c(0,0)) +
#Change axis looks
#theme(axis.title=element_text(size=16, color='dimgray', face='bold'),
#axis.text=element_text(size=16, color='dimgray'),
#axis.line = element_line(color='dimgray', size=1, linetype='solid'),
#axis.ticks = element_line(color='dimgray', size=1, linetype='solid')) +
#axis.line.x = element_line(color='white', size=1, linetype='solid'),
#axis.ticks.x = element_line(color='white', size=1, linetype='solid')) +
#theme(plot.margin=unit(c(0.1,0,0,0), "null"),
#axis.title.y=element_text(angle=0, vjust=1.075, margin=margin(t=0, r=-55, b=0, l=0)))
#Change axis looks
theme(axis.title=element_text(size=18, color='dimgray', face='bold'),
axis.text=element_text(size=18, color='dimgray'),
axis.line = element_line(color='dimgray', size=1, linetype='solid'),
axis.ticks = element_line(color='dimgray', size=1, linetype='solid'),
plot.title = element_text(size=20, color='dimgray', face='bold', hjust=0.5),
legend.title=element_text(size=16, color='dimgray', face='bold'),
legend.text=element_text(size=14, color='dimgray'),
#legend.position=c(.54, -.225),
axis.text.y=element_blank(),
aspect.ratio=1)
ggsave("Representative sample_vertical.png", width = 6, height = 4, dpi=600)
ggsave("Representative sample_vertical.svg", width = 6, height = 4, dpi=600)
################################################################################
#Plot data - horizontal
my_colors = c('#BABABA', '#A9A9A9')
g <- ggplot(data, aes(fill=fct_rev(fill), x=fct_rev(continents), y=count, widths=.8)) +
geom_bar(stat='identity', position=position_dodge(.8)) +
#Switch orientation
coord_flip() +
#Add percentage labels to the individual bars
geom_text(aes(x=fct_rev(continents), y=count, label=paste0(sprintf("%4.0f", round(count, digits=0)), '%'),
group=fct_rev(fill)), vjust=0.5, hjust=0.3,
position=position_dodge(.8),
family='sans', size=3.5, fontface='bold', color='dimgray') +
#Adjust colors
scale_fill_manual(values=my_colors, labels=c('Pubmed authors', 'Analysts')) +
#Adjust legend
theme(legend.title=element_text(size=12, color='dimgray', face='bold'),
legend.position=c(.825, .9),
legend.text=element_text(size=12, color='dimgray')) +
guides(fill=guide_legend(reverse=TRUE)) +
#Change axis labels
labs(x=' ', y='Percent', fill='Sample') +
#Change the aspect ratio of the plot
theme(aspect.ratio=.3) +
#Remove unnecessary white space between axis and bars
scale_x_discrete(expand=c(0,0)) +
scale_y_continuous(limits=c(0, 73), expand=c(0,0)) +
#Change axis looks
theme(axis.title=element_text(size=16, color='dimgray', face='bold'),
axis.text=element_text(size=16, color='dimgray'),
axis.line = element_line(color='dimgray', size=1, linetype='solid'),
axis.ticks = element_line(color='dimgray', size=1, linetype='solid'))
#axis.line.x = element_line(color='white', size=1, linetype='solid'),
#axis.ticks.x = element_line(color='white', size=1, linetype='solid')) +
#theme(plot.margin=unit(c(0.1,0,0,0), "null"),
#axis.title.y=element_text(angle=0, vjust=1.075, margin=margin(t=0, r=-55, b=0, l=0)))
ggsave("Representative sample_horizontal.png", width = 6, height = 4, dpi=600)