-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 24.8 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
sizes = c(2.5, 2)
names(colors) <- levels(df$system)
names(colors_means) <- levels(df$system)
names(sizes) <- levels(df$system)
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean = mean(gamma_sample))
df_mean$system = factor(df_mean$system, levels = c("Non-linear \n(Fold)", "Linear"))
df$alpha <- factor(df$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
df_mean$alpha <- factor(df_mean$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_line(data = df, aes(x = k, y = gamma_true, color = "Theory", linetype = "Theory", shape = "Theory"), linewidth = .75) +
facet_wrap(~rev(alpha), labeller = label_parsed, nrow = 1) +
geom_point(data = df, aes(x = k, y = gamma_sample, color = system, shape = system, linetype = system),
stroke = 0.2, position = position_jitter(width = .25), size = 0.25, alpha = .4) +
geom_point(data = df_mean, aes(x = k, y = mean, color = system, shape = system, size = system, linetype = system),
stroke = 1) +
scale_size_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 3, "Theory" = 3), name = "System") +
scale_shape_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 4, "Theory" = 21), name = "System") +
scale_color_manual(values = c("Linear" = "#56B4E9", "Non-linear \n(Fold)" = "#E69F00", "Theory" = "#D55E00"), name = "System") +
scale_linetype_manual(values = c("Linear" = "solid", "Non-linear \n(Fold)" = "solid", "Theory" = "dashed"), name = "System") +
scale_y_continuous(trans = 'log10', name = expression(EWS~gamma[X]), expand = c(0,0)) +
scale_x_continuous(trans = 'log10', name = "Bifurcation parameter k",
breaks = c(0.01, 1, 100), labels = c("0.01", "1", "100"),expand = c(0,0)) +
theme(axis.text.x = element_text(hjust = 0.75, size = 15),
legend.position = "bottom",
legend.direction = "horizontal") +
guides(size = "none"))
return(p)
}
plot_gamma_eq()
ggsave("reports/paper/gamma_equilibrium_diss.pdf", width = 9.5, height = 4, scale = 1)
#gamma non-equilibrium runs
plot_gamma_neq = function(A =c(1.3, 1.5, 1.8, 2), cutoff_theory = .15) {
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows) %>%
filter(timestep > 1000) %>%
group_by(alpha, system, sample) %>%
arrange(alpha, system, sample, k) %>%
mutate(gamma_smoothed = slider::slide_dbl(gamma_sample, mean, .before =50, .after = 50)) %>%
filter(gamma_true < cutoff_theory,
gamma_smoothed < cutoff_theory)
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean_gamma = mean(gamma_smoothed, na.rm = TRUE)) %>%
group_by(system) %>%
mutate(mean_max = max(mean_gamma),
mean_min = min(mean_gamma)) %>%
ungroup()
df$alpha_label <- factor(df$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
df_mean$alpha_label <- factor(df_mean$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
legend_labels = (c(TeX("$\\alpha$ = 2"), TeX("$\\alpha$ = 1.8"), TeX("$\\alpha$ = 1.5"), TeX("$\\alpha$ = 1.3"), "Theory"))
colors = rev(c("2" = "black", "1.8" = "#0072B2", "1.5" = "#009E73", "1.3" = "#56B4E9", "Theory" = "#D55E00"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), limits = c(0.025, 0.08), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))
return(p)
}
plot_gamma_neq()
#gamma non-equilibrium runs
plot_gamma_neq = function(A =c(1.3, 1.5, 1.8, 2), cutoff_theory = .15) {
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows) %>%
filter(timestep > 1000) %>%
group_by(alpha, system, sample) %>%
arrange(alpha, system, sample, k) %>%
mutate(gamma_smoothed = slider::slide_dbl(gamma_sample, mean, .before =50, .after = 50)) %>%
filter(gamma_true < cutoff_theory,
gamma_smoothed < cutoff_theory)
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean_gamma = mean(gamma_smoothed, na.rm = TRUE)) %>%
group_by(system) %>%
mutate(mean_max = max(mean_gamma),
mean_min = min(mean_gamma)) %>%
ungroup()
df$alpha_label <- factor(df$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
df_mean$alpha_label <- factor(df_mean$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
legend_labels = (c(TeX("$\\alpha$ = 2"), TeX("$\\alpha$ = 1.8"), TeX("$\\alpha$ = 1.5"), TeX("$\\alpha$ = 1.3"), "Theory"))
colors = rev(c("2" = "black", "1.8" = "#0072B2", "1.5" = "#009E73", "1.3" = "#56B4E9", "Theory" = "#D55E00"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), limits = c(0.025, 0.09), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))
return(p)
}
plot_gamma_neq()
plot_gamma_neq()
ggsave("reports/paper/gamma_noneq_diss.pdf", width = 10, height = 6, scale = 1)
plot_0.9 = function() {
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows) %>%
filter(timestep > 1000) %>%
group_by(alpha, system, sample) %>%
arrange(alpha, system, sample, k) %>%
mutate(gamma_smoothed = slider::slide_dbl(gamma_sample, mean, .before =50, .after = 50))
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean_gamma = mean(gamma_smoothed, na.rm = TRUE)) %>%
group_by(system) %>%
ungroup()
df$alpha_label <- factor(df$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
df_mean$alpha_label <- factor(df_mean$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
legend_labels = (c(TeX("$\\alpha$ = 2"), TeX("$\\alpha$ = 1.8"), TeX("$\\alpha$ = 1.5"), TeX("$\\alpha$ = 1.3"), TeX("$\\alpha$ = 0.9"),, "Theory"))
colors = rev(c("2" = "black", "1.8" = "#0072B2", "1.5" = "#009E73", "1.3" = "#56B4E9", "0.9" = "#56B4E9", "Theory" = "#D55E00"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))
}
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
A = 0.9
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows) %>%
filter(timestep > 1000) %>%
group_by(alpha, system, sample) %>%
arrange(alpha, system, sample, k) %>%
mutate(gamma_smoothed = slider::slide_dbl(gamma_sample, mean, .before =50, .after = 50))
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean_gamma = mean(gamma_smoothed, na.rm = TRUE)) %>%
group_by(system) %>%
ungroup()
df$alpha_label <- factor(df$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
df_mean$alpha_label <- factor(df_mean$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
legend_labels = (c(TeX("$\\alpha$ = 2"), TeX("$\\alpha$ = 1.8"), TeX("$\\alpha$ = 1.5"), TeX("$\\alpha$ = 1.3"), TeX("$\\alpha$ = 0.9"),, "Theory"))
colors = rev(c("2" = "black", "1.8" = "#0072B2", "1.5" = "#009E73", "1.3" = "#56B4E9", "0.9" = "#56B4E9", "Theory" = "#D55E00"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_eq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a))
df_nol = read.csv(paste0("data/gamma_nol_eq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a))
df = df_nol %>%
full_join(df) %>%
filter(gamma_sample < 10^40) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows)
df$system = factor(df$system, levels = c("Linear", "Non-linear \n(Fold)"))
colors = c("#000000", "#98C6EA")
colors_means = c("#56B4E9", "#E69F00")
line_color = c("Theory" = "#D55E00")
sizes = c(2.5, 2)
names(colors) <- levels(df$system)
names(colors_means) <- levels(df$system)
names(sizes) <- levels(df$system)
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean = mean(gamma_sample))
df_mean$system = factor(df_mean$system, levels = c("Non-linear \n(Fold)", "Linear"))
df$alpha <- factor(df$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
df_mean$alpha <- factor(df_mean$alpha,
levels = rev(c(2, 1.8, 1.5, 1.3)),
labels=rev(c('2'=parse(text=TeX('$\\alpha$ = 2')),
'1.8'=parse(text=TeX('$\\alpha$ = 1.8')),
'1.5'=parse(text=TeX('$\\alpha$ = 1.5')),
'1.3'=parse(text=TeX('$\\alpha$ = 1.3')))))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_line(data = df, aes(x = k, y = gamma_true, color = "Theory", linetype = "Theory", shape = "Theory"), linewidth = .75) +
facet_wrap(~rev(alpha), labeller = label_parsed, nrow = 1) +
geom_point(data = df, aes(x = k, y = gamma_sample, color = system, shape = system, linetype = system),
stroke = 0.2, position = position_jitter(width = .25), size = 0.25, alpha = .4) +
geom_point(data = df_mean, aes(x = k, y = mean, color = system, shape = system, size = system, linetype = system),
stroke = 1) +
scale_size_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 3, "Theory" = 3), name = "System") +
scale_shape_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 4, "Theory" = 21), name = "System") +
scale_color_manual(values = c("Linear" = "#56B4E9", "Non-linear \n(Fold)" = "#E69F00", "Theory" = "#D55E00"), name = "System") +
scale_linetype_manual(values = c("Linear" = "solid", "Non-linear \n(Fold)" = "solid", "Theory" = "dashed"), name = "System") +
scale_y_continuous(trans = 'log10', name = expression(EWS~gamma[X]), expand = c(0,0)) +
scale_x_continuous(trans = 'log10', name = "Bifurcation parameter k",
breaks = c(0.01, 1, 100), labels = c("0.01", "1", "100"),expand = c(0,0)) +
theme(axis.text.x = element_text(hjust = 0.75, size = 15),
legend.position = "bottom",
legend.direction = "horizontal") +
guides(size = "none"))
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_eq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a))
df_nol = read.csv(paste0("data/gamma_nol_eq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a))
df = df_nol %>%
full_join(df) %>%
filter(gamma_sample < 10^40) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
df = purrr::reduce(data, bind_rows)
df$system = factor(df$system, levels = c("Linear", "Non-linear \n(Fold)"))
colors = c("#000000", "#98C6EA")
colors_means = c("#56B4E9", "#E69F00")
line_color = c("Theory" = "#D55E00")
sizes = c(2.5, 2)
names(colors) <- levels(df$system)
names(colors_means) <- levels(df$system)
names(sizes) <- levels(df$system)
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean = mean(gamma_sample))
df_mean$system = factor(df_mean$system, levels = c("Non-linear \n(Fold)", "Linear"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_line(data = df, aes(x = k, y = gamma_true, color = "Theory", linetype = "Theory", shape = "Theory"), linewidth = .75) +
facet_wrap(~rev(alpha), labeller = label_parsed, nrow = 1) +
geom_point(data = df, aes(x = k, y = gamma_sample, color = system, shape = system, linetype = system),
stroke = 0.2, position = position_jitter(width = .25), size = 0.25, alpha = .4) +
geom_point(data = df_mean, aes(x = k, y = mean, color = system, shape = system, size = system, linetype = system),
stroke = 1) +
scale_size_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 3, "Theory" = 3), name = "System") +
scale_shape_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 4, "Theory" = 21), name = "System") +
scale_color_manual(values = c("Linear" = "#56B4E9", "Non-linear \n(Fold)" = "#E69F00", "Theory" = "#D55E00"), name = "System") +
scale_linetype_manual(values = c("Linear" = "solid", "Non-linear \n(Fold)" = "solid", "Theory" = "dashed"), name = "System") +
scale_y_continuous(trans = 'log10', name = expression(EWS~gamma[X]), expand = c(0,0)) +
scale_x_continuous(trans = 'log10', name = "Bifurcation parameter k",
breaks = c(0.01, 1, 100), labels = c("0.01", "1", "100"),expand = c(0,0)) +
theme(axis.text.x = element_text(hjust = 0.75, size = 15),
legend.position = "bottom",
legend.direction = "horizontal") +
guides(size = "none"))
df$alpha <- factor(df$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
df_mean$alpha <- factor(df_mean$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_line(data = df, aes(x = k, y = gamma_true, color = "Theory", linetype = "Theory", shape = "Theory"), linewidth = .75) +
facet_wrap(~rev(alpha), labeller = label_parsed, nrow = 1) +
geom_point(data = df, aes(x = k, y = gamma_sample, color = system, shape = system, linetype = system),
stroke = 0.2, position = position_jitter(width = .25), size = 0.25, alpha = .4) +
geom_point(data = df_mean, aes(x = k, y = mean, color = system, shape = system, size = system, linetype = system),
stroke = 1) +
scale_size_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 3, "Theory" = 3), name = "System") +
scale_shape_manual(values = c("Linear" = 3, "Non-linear \n(Fold)" = 4, "Theory" = 21), name = "System") +
scale_color_manual(values = c("Linear" = "#56B4E9", "Non-linear \n(Fold)" = "#E69F00", "Theory" = "#D55E00"), name = "System") +
scale_linetype_manual(values = c("Linear" = "solid", "Non-linear \n(Fold)" = "solid", "Theory" = "dashed"), name = "System") +
scale_y_continuous(trans = 'log10', name = expression(EWS~gamma[X]), expand = c(0,0)) +
scale_x_continuous(trans = 'log10', name = "Bifurcation parameter k",
breaks = c(0.01, 1, 100), labels = c("0.01", "1", "100"),expand = c(0,0)) +
theme(axis.text.x = element_text(hjust = 0.75, size = 15),
legend.position = "bottom",
legend.direction = "horizontal") +
guides(size = "none"))
data = list()
for (a in A) {
df = read.csv(paste0("data/gamma_lin_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Linear",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df_nol = read.csv(paste0("data/gamma_nol_neq_alpha", a, ".csv")) %>%
filter(k != 0) %>%
mutate(system = "Non-linear \n(Fold)",
alpha = paste0(a)) %>%
filter(gamma_sample != 0)
df = df_nol %>%
full_join(df) %>%
mutate(gamma_true = 0.1*(1/(a*k))^(1/a))
data = append(data, list(df))
}
View(df)
df = purrr::reduce(data, bind_rows) %>%
filter(timestep > 1000) %>%
group_by(alpha, system, sample) %>%
arrange(alpha, system, sample, k) %>%
mutate(gamma_smoothed = slider::slide_dbl(gamma_sample, mean, .before =50, .after = 50))
df_mean = df %>%
group_by(alpha, k, system) %>%
summarize(mean_gamma = mean(gamma_smoothed, na.rm = TRUE)) %>%
group_by(system) %>%
ungroup()
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))
df$alpha_label <- factor(df$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
df_mean$alpha_label <- factor(df_mean$alpha,
levels = rev(c(0.9)),
labels=rev(c('0.9'=parse(text=TeX('$\\alpha$ = 0.9')))))
legend_labels = (c(TeX("$\\alpha$ = 2"), TeX("$\\alpha$ = 1.8"), TeX("$\\alpha$ = 1.5"), TeX("$\\alpha$ = 1.3"), TeX("$\\alpha$ = 0.9"),, "Theory"))
colors = rev(c("2" = "black", "1.8" = "#0072B2", "1.5" = "#009E73", "1.3" = "#56B4E9", "0.9" = "#56B4E9", "Theory" = "#D55E00"))
(p = ggplot() +
geom_vline(xintercept = 0, color = "black", linewidth = .75) +
geom_hline(yintercept = 0.025, color = "black", linewidth = 0.75) +
geom_line(data = df, aes(x = k, y = gamma_smoothed, group = interaction(run, alpha), color = as.factor(alpha), linetype = "Simulation"),
alpha = .75, linewidth = .001) +
geom_line(data = df[df$system == "Linear",], aes(x = k, y = gamma_true, group = interaction(system, alpha),
color = "Theory", linetype = "Theory"), linewidth = .6) +
geom_line(data = df_mean, aes(x = k, y = mean_gamma, color = as.factor(alpha), linetype = "Simulation"),
alpha = .9, linewidth = .7) +
scale_color_manual(values = colors, name = expression(~gamma[X])) +
scale_linetype_manual(values = c("Theory" = "dashed", "Simulation" = "solid"), name = expression(~gamma[X])) +
scale_x_continuous(limits = c(0.25, 5), expand = c(0,0), breaks = c(1, 3, 5), name = expression(symbol('\254')~~~Bifurcation~parameter~k)) +
scale_y_continuous(name = expression(gamma[X]), expand = c(0,0), breaks = c(0, 0.05, 0.075)) +
facet_grid(rows = vars(system), cols = vars(alpha_label), scales = "free", labeller = label_parsed) +
theme(legend.position = "bottom",
legend.direction = "horizontal") +
guides(color = guide_legend(ncol = 4, byrow = TRUE),
linetype = "none"))