/
make_all_figures_v4.R
1858 lines (1475 loc) · 84.1 KB
/
make_all_figures_v4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Script to make all figures for SIVS NK manuscript
# Ryland Mortlock
# October 2021
## Install required libraries ###################################################
# install.packages("ggplot2")
# install.packages("reshape2")
# install.packages("dplyr")
# install.packages("ggpubr")
# install.packages("RColorBrewer")
# install.packages("networkD3")
# install.packages("plyr")
# install.packages("pheatmap")
## Load required libraries ###################################################
library(ggplot2)
library(reshape2)
library(dplyr)
library(ggpubr)
library(RColorBrewer)
library(networkD3)
library(plyr)
library(pheatmap)
# Set directories
data_dir <- "data_files_for_manuscript"
results_dir <- "R_plots"
# Function to get summary statistic
#+++++++++++++++++++++++++
# Function to calculate the mean and the standard deviation
# for each group
#+++++++++++++++++++++++++
# data : a data frame
# varname : the name of a column containing the variable
#to be summariezed
# groupnames : vector of column names to be used as
# grouping variables
data_summary_sd <- function(data, varname, groupnames){
require(plyr)
summary_func <- function(x, col){
c(mean = mean(x[[col]], na.rm=TRUE),
sd = sd(x[[col]], na.rm=TRUE))
}
data_sum<-ddply(data, groupnames, .fun=summary_func,
varname)
data_sum <- rename(data_sum, c("mean" = varname))
return(data_sum)
}
data_summary_se <- function(data, varname, groupnames){
require(plyr)
summary_func <- function(x, col){
c(mean = mean(x[[col]], na.rm=TRUE),
se = sd(x[[col]], na.rm=TRUE)/sqrt(length(!is.na(x[[col]]))))
}
data_sum<-ddply(data, groupnames, .fun=summary_func,
varname)
data_sum <- rename(data_sum, c("mean" = varname))
return(data_sum)
}
## Box plot of NK proportions across tissues ###################################################
# Load subset proportionos data
NK_prop <- read.csv(file = file.path(data_dir, "NK_proportion_of_lymphocytes.csv"))
# Set AxLN tissues as LN for SIVS SAMPLES
NK_prop$Tissue[grepl("Ax_LN",NK_prop$Tissue)] <- "Lymph Node"
# Order factors
NK_prop$Tissue <- factor(NK_prop$Tissue, levels = c("Blood","Bone Marrow","Lymph Node","Spleen",
"Liver","Lung", "Jejunum",
"BAL", "Colon", "Ing_LN", "Mes_LN"))
# Only keep the tissues we want to show
NK_prop <- NK_prop[NK_prop$Tissue %in% c("Blood","Bone Marrow","Lymph Node","Spleen","Liver","Lung", "Jejunum"),]
NK_prop$Tissue <- as.character(NK_prop$Tissue)
# Add number of data points to the label
for (my_tissue in unique(NK_prop$Tissue)){
NK_prop$Tissue[NK_prop$Tissue == my_tissue] <- paste0(NK_prop$Tissue[NK_prop$Tissue == my_tissue], "\nn = ",
length(NK_prop$Tissue[NK_prop$Tissue == my_tissue]))
}
NK_prop$Tissue <- factor(NK_prop$Tissue, levels = c(NK_prop$Tissue[grep("Blood", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Bone Marrow", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Lymph Node", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Spleen", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Liver", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Lung", NK_prop$Tissue)[1]],
NK_prop$Tissue[grep("Jejunum", NK_prop$Tissue)[1]]))
# Make box plot
p <- ggplot(NK_prop, aes(x = Tissue, y = Percentage)) +
geom_boxplot(fill = "firebrick", color = "black", size = 0.5, outlier.shape = NA, width = 0.6) +
stat_boxplot(geom = 'errorbar', size = 0.5, width = 0.3) +
geom_jitter(shape=16, position=position_jitter(0.2), size = 2) +
theme_classic() + labs(y = "NK Cell Percentage of Lymphocytes") +
theme(axis.title.x = element_blank(),
axis.title.y = element_text(size = 12, color = "black"),
axis.text.x = element_text(size = 12, color = "black"),
axis.text.y = element_text(size = 12, color = "black"))
# Print to PDF
pdf(file = file.path(results_dir, "NK_proportion_of_lymphocytes.pdf"), width = 8, height = 4)
plot(p)
dev.off()
## Box plot of NK subset percentages across tissues ###################################################
# Load subset proportions data
NK_subset_proportions <- read.csv(file = file.path(data_dir, "NK_subset_proportions.csv"))
# Set AxLN tissues as LN for SIVS SAMPLES
NK_subset_proportions$Tissue[grepl("Ax_LN",NK_subset_proportions$Tissue)] <- "Lymph Node"
# Order factors
NK_subset_proportions$Tissue <- factor(NK_subset_proportions$Tissue, levels = c("Blood","Bone Marrow","Lymph Node","Spleen",
"Liver","Lung", "Jejunum",
"BAL", "Colon", "Ing_LN", "Mes_LN"))
# Only keep the tissues we want to show
NK_subset_proportions <- NK_subset_proportions[NK_subset_proportions$Tissue %in% c("Blood","Bone Marrow","Lymph Node","Spleen","Liver","Lung", "Jejunum"),]
NK_subset_proportions$Tissue <- as.character(NK_subset_proportions$Tissue)
# Add number of data points to the label
for (my_tissue in unique(NK_subset_proportions$Tissue)){
NK_subset_proportions$Tissue[NK_subset_proportions$Tissue == my_tissue] <- paste0(NK_subset_proportions$Tissue[NK_subset_proportions$Tissue == my_tissue], "\nn = ",
length(NK_subset_proportions$Tissue[NK_subset_proportions$Tissue == my_tissue]))
}
NK_subset_proportions$Tissue <- factor(NK_subset_proportions$Tissue, levels = c(NK_subset_proportions$Tissue[grep("Blood", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Bone Marrow", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Lymph Node", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Spleen", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Liver", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Lung", NK_subset_proportions$Tissue)[1]],
NK_subset_proportions$Tissue[grep("Jejunum", NK_subset_proportions$Tissue)[1]]))
# Melt into long formast
NK_subset_long <- reshape2::melt(NK_subset_proportions, id.vars = "Tissue", measure.vars = c("CD16_NK", "CD56_NK", "DN_NK"))
# Rename subsets
NK_subset_long$variable <- gsub("_", " ", NK_subset_long$variable)
# Order factors
NK_subset_long$variable <- gsub("CD56 NK", "CD56+ NK", NK_subset_long$variable)
NK_subset_long$variable <- gsub("CD16 NK", "CD16+ NK", NK_subset_long$variable)
NK_subset_long$variable <- factor(NK_subset_long$variable, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Make grouped box plot
p <- ggplot(NK_subset_long, aes(x = Tissue, y = value, fill = variable)) +
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3) +
geom_point(position=position_jitterdodge(0.1), size = 1) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
theme_classic() + labs(y = "Percentage of NK Cells") +
theme(axis.title.x = element_blank(),
axis.title.y = element_text(size = 12, color = "black"),
axis.text.x = element_text(size = 12, color = "black"),
axis.text.y = element_text(size = 12, color = "black"),
legend.position = "top",
legend.justification = "left",
legend.title = element_blank(),
legend.text = element_text(size = 12, color = "black"))
# Print to PDF
pdf(file = file.path(results_dir, "NK_subset_percentages.pdf"), width = 8, height = 4.6)
plot(p)
dev.off()
## Sankey plot of animal G45T peripheral blood data ###################################################
# Read data
sankey_data <- read.csv(file = file.path(data_dir,'G45T_PB_data_for_Sankey.csv'))
# CD56 NK
links <- sankey_data[sankey_data$cell_type == "CD56 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Purples")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#54278F", "#9E9AC8"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# DN NK
links <- sankey_data[sankey_data$cell_type == "DN NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Greens")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#006D2C", "#74C476"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# CD16 NK
links <- sankey_data[sankey_data$cell_type == "CD16 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Blues")[c(9,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#08306B", "#6BAED6"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
## Sankey plot of animal DGA0 peripheral blood data ###################################################
# Read data
sankey_data <- read.csv(file = file.path(data_dir,'DGA0_PB_data_for_Sankey.csv'))
# CD56 NK
links <- sankey_data[sankey_data$cell_type == "CD56 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Purples")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#54278F", "#9E9AC8"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# Repeat for DN NK
links <- sankey_data[sankey_data$cell_type == "DN NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Greens")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#006D2C", "#74C476"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# Repeat for CD16 NK
links <- sankey_data[sankey_data$cell_type == "CD16 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Blues")[c(9,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#08306B", "#6BAED6"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
## Sankey plot of animal DGF5 peripheral blood data ###################################################
# Read data
sankey_data <- read.csv(file = file.path(data_dir,'DGF5_PB_data_for_Sankey.csv'))
# CD56 NK
links <- sankey_data[sankey_data$cell_type == "CD56 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Purples")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#54278F", "#9E9AC8"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# DN NK
links <- sankey_data[sankey_data$cell_type == "DN NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Greens")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#006D2C", "#74C476"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# CD16 NK
links <- sankey_data[sankey_data$cell_type == "CD16 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b"))
brewer.pal(9, "Blues")[c(9,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#08306B", "#6BAED6"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
## Sankey plot of animal TID peripheral blood data ###################################################
# Read data
sankey_data <- read.csv(file = file.path(data_dir,'TID_PB_data_for_Sankey.csv'))
# CD56 NK
links <- sankey_data[sankey_data$cell_type == "CD56 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Purples")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#54278F", "#9E9AC8"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# DN NK
links <- sankey_data[sankey_data$cell_type == "DN NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Greens")[c(8,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#006D2C", "#74C476"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
# CD16 NK
links <- sankey_data[sankey_data$cell_type == "CD16 NK", 2:4]
# From these flows we need to create a node data frame: it lists every entities involved in the flow
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
# With networkD3, connection must be provided using id, not using real name like in the links dataframe.. So we need to reformat it.
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
# Color nodes
nodes$group <- as.factor(c("a","b","a","b","a","b","a","b"))
brewer.pal(9, "Blues")[c(9,5)]
my_color <- 'd3.scaleOrdinal() .domain(["a", "b"]) .range(["#08306B", "#6BAED6"])'
# Make the Network
p <- sankeyNetwork(Links = links, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
sinksRight=TRUE, fontSize = 18,
height = 300, width = 450,
colourScale = my_color, NodeGroup = "group")
p
## Bar plot of long term circulating proportions ###################################################
# Read the data
lt_circ_prop <- read.csv(file = file.path(data_dir, 'PB_long_term_circulating_proportions_with_T.csv'))
# Ensure the order of factors
lt_circ_prop$Cell_Type <- gsub("CD56 NK", "CD56+ NK", lt_circ_prop$Cell_Type)
lt_circ_prop$Cell_Type <- gsub("CD16 NK", "CD16+ NK", lt_circ_prop$Cell_Type)
lt_circ_prop$Cell_Type <- factor(lt_circ_prop$Cell_Type, levels = c("T Cell", "CD56+ NK", "DN NK", "CD16+ NK"))
# Calculate standard error
lt_circ_prop_summary <- data_summary_se(lt_circ_prop, varname="percentage",
groupnames=c("Animal", "Cell_Type"))
# Ensure the order of factors
lt_circ_prop_summary$Animal <- factor(lt_circ_prop_summary$Animal, levels = c("DGA0 6hr", "DGF5 6hr","G45T 6hr", "TID 6hr", "G45T 48hr", "TID 48hr"))
# Replace space with new line
lt_circ_prop_summary$Animal <- gsub(" ", "\n-", lt_circ_prop_summary$Animal)
lt_circ_prop_summary$Animal <- factor(lt_circ_prop_summary$Animal, levels = c( "DGA0\n-6hr", "DGF5\n-6hr","G45T\n-6hr", "TID\n-6hr", "G45T\n-48hr", "TID\n-48hr"))
# Rename columns
colnames(lt_circ_prop_summary)[2] <- "Cell Type"
colnames(lt_circ_prop_summary)[3] <- "value"
# Bar chart with error bars on top
p <- ggplot(lt_circ_prop_summary, aes(x=Animal, y=value, fill=`Cell Type`)) +
geom_bar(stat="identity", color="black", position=position_dodge(), width = 0.75) +
geom_errorbar(aes(ymin=value, ymax=value+se), width=.2,
position=position_dodge(.75)) + theme_classic() +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(1,4,3,2)]) + labs(title = "", y = "Percentage Continuously Circulating") +
# scale_x_discrete(labels = levels(lt_circ_prop_summary$Animal)) +
theme(axis.title.x = element_blank(), axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)), title = element_blank(),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(size = 14, color = "black"), axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_text(size = 14, color = "black", face = "bold"), legend.text = element_text(size = 14, color = "black"))
pdf(file = file.path(results_dir, "PB_long_term_circulating_percentages_with_T_cells.pdf"), width = 7*6/4, height = 4)
plot(p)
dev.off()
## Make dot plot comparing mean lt-circulating proportion of the 3 biological replicates ###################################################
# Load means from 6 hour positive proportions [means from previous plot normalized to lymphocyte percentage]
means_6hr <- read.csv(file = file.path(data_dir, "PB_6hr_means.csv"))
# Ensure the order of factors
means_6hr$Cell_Type <- gsub("CD56 NK", "CD56+ NK", means_6hr$Cell_Type)
means_6hr$Cell_Type <- gsub("CD16 NK", "CD16+ NK", means_6hr$Cell_Type)
means_6hr$Cell_Type <- factor(means_6hr$Cell_Type, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Box plot with wilcoxon test to compare means
my_comparisons <- list( c("CD56+ NK", "DN NK"), c("DN NK", "CD16+ NK"), c("CD56+ NK", "CD16+ NK") )
p <- ggplot(means_6hr, aes(x = Cell_Type, y = value, fill = Cell_Type)) +
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3, coef = 5) +
stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", paired = F,
label.y = c(100, 110, 120)) +
geom_point(position=position_jitterdodge(0.1), size = 2.5) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
labs(title = "", y = "Percentage Continuously Circulating") +
theme_classic() +
theme(title = element_blank(),
plot.title = element_text(hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
axis.title.x = element_blank(),
axis.text.y = element_text(size = 14, color = "black"),
axis.text.x = element_text(size = 14, color = "black"),
legend.position = "none")+
scale_y_continuous(breaks=seq(0,100,25))
pdf(file = file.path(results_dir, "PB_6hour_proportions_boxplot.pdf"), width = 4, height = 4)
plot(p)
dev.off()
## Peripheral blood summary plot across animals ###################################################
# Read PB data
PB_data <- read.csv(file = file.path(data_dir, 'Summary_data_by_tissue_PB_with_T.csv'))
# Melt into long format
PB_data_long <- reshape2::melt(PB_data, id = c("Animal","Cell_Type"))
# Ensure the order of my factors
PB_data_long$Animal <- factor(PB_data_long$Animal, levels = c("DGA0", "DGF5", "G45T", "TID"))
PB_data_long$Cell_Type <- gsub("CD56 NK", "CD56+ NK", PB_data_long$Cell_Type)
PB_data_long$Cell_Type <- gsub("CD16 NK", "CD16+ NK", PB_data_long$Cell_Type)
PB_data_long$Cell_Type <- factor(PB_data_long$Cell_Type, levels = c("T Cell", "CD56+ NK", "DN NK", "CD16+ NK"))
# Rename Cell_Type column
colnames(PB_data_long)[2] <- "Cell Type"
# Rename the SIVS variable and ensure order
PB_data_long$variable <- gsub("SIVS_","", as.character(PB_data_long$variable))
PB_data_long$variable <- factor(PB_data_long$variable, levels = c("48hr", "24hr", "6hr", "2hr", "5min"))
PB_data_long$variable <- paste0("-",PB_data_long$variable)
PB_data_long$variable <- factor(PB_data_long$variable, levels = c("-48hr", "-24hr", "-6hr", "-2hr", "-5min"))
PB_data_long <- na.omit(PB_data_long)
# Make bar plot
p <- ggbarplot(PB_data_long, x = "variable", y = "value",
add = c("mean_se", "jitter"),
color = "Cell Type", shape = "Animal", fill = "grey95",
size = 0.8,
palette = brewer.pal(4, name = "Set1")[c(1,4,3,2)],
position = position_dodge(0.8)) +
labs(x = "SIVS Infusion", y = "Percentage SIVS Positive") +
theme(legend.position = "right",
axis.text.x = element_text(size = 14, color = "black"),
axis.text.y = element_text(size = 14, color = "black"),
axis.title.x = element_text(size = 14, color = "black"),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
legend.title = element_text(size = 14, color = "black", face = "bold"),
legend.text = element_text(size = 14, color = "black")) +
guides(
color = guide_legend(order = 1),
shape = guide_legend(order = 0)
)
# Save plot to PDF
pdf(file = file.path(results_dir, "PB_summary_figure_with_T.pdf"), width = 12, height = 5)
plot(p)
dev.off()
## Bar plot of IVAS+ percentages in lymph node ###################################################
# Read the data
LN_ivas_prop <- read.csv(file = file.path(data_dir, 'LN_IVAS_positive_proportions.csv'))
# # Exclude lymphocytes
# LN_ivas_prop <- LN_ivas_prop[LN_ivas_prop$Cell_Type %in% c("CD56 NK", "DN NK", "CD16 NK"),]
# Ensure the order of factors
LN_ivas_prop$Cell_Type <- gsub("CD56 NK", "CD56+ NK", LN_ivas_prop$Cell_Type)
LN_ivas_prop$Cell_Type <- gsub("CD16 NK", "CD16+ NK", LN_ivas_prop$Cell_Type)
LN_ivas_prop$Cell_Type <- factor(LN_ivas_prop$Cell_Type, levels = c("T Cell","CD56+ NK", "DN NK", "CD16+ NK"))
# Calculate stadard deviation
LN_ivas_prop_summary <- data_summary_se(LN_ivas_prop, varname="ivas_percentage",
groupnames=c("Animal", "Cell_Type"))
# Rename colums
colnames(LN_ivas_prop_summary)[2] <- "Cell Type"
colnames(LN_ivas_prop_summary)[3] <- "value"
# Bar chart with error bars on top
p <- ggplot(LN_ivas_prop_summary, aes(x=Animal, y=value, fill=`Cell Type`)) +
geom_bar(stat="identity", color="black", position=position_dodge(), width = 0.75) +
geom_errorbar(aes(ymin=value, ymax=value+se), width=.2,
position=position_dodge(.75)) + theme_classic() +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(1,4,3,2)]) + labs(y = "Percentage IVas+") +
theme(axis.title.x = element_blank(),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
title = element_blank(),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(size = 14, color = "black"), axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_text(size = 14, color = "black", face = "bold"),
legend.text = element_text(size = 14, color = "black"))
pdf(file = file.path(results_dir, "LN_IVAS_positive_percentages_with_T.pdf"), width = 10*6/5, height = 4)
plot(p)
dev.off()
## LN IVAS+ summary dot plot 6hr ###################################################
# Load means normalized to T cell
means_ivas <- read.csv(file = file.path(data_dir, "LN_IVAS_positive_proportions_mean_dotplot.csv"))
# Ensure the order of factors
means_ivas$Cell_Type <- gsub("CD56 NK", "CD56+ NK", means_ivas$Cell_Type)
means_ivas$Cell_Type <- gsub("CD16 NK", "CD16+ NK", means_ivas$Cell_Type)
means_ivas$Cell_Type <- factor(means_ivas$Cell_Type, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Box plot with wilcoxon test to compare means
my_comparisons <- list( c("CD56+ NK", "DN NK"), c("DN NK", "CD16+ NK"), c("CD56+ NK", "CD16+ NK") )
p <- ggplot(means_ivas, aes(x = Cell_Type, y = value, fill = Cell_Type)) +
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3, coef = 5) +
stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", paired = F,
label.y = c(log10(100), log10(150), log10(250))) +
geom_point(position=position_jitterdodge(0.1), size = 2.5) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
scale_y_continuous(trans = "log10") +
labs(title = "", y = "Percentage IVas+ (log scale)") +
theme_classic() +
theme(title = element_blank(),
plot.title = element_text(hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
axis.title.x = element_blank(),
axis.text.y = element_text(size = 14, color = "black"),
axis.text.x = element_text(size = 14, color = "black"),
legend.position = "none")
pdf(file = file.path(results_dir, "LN_IVAS_positive_boxplot.pdf"), width = 4, height = 4)
plot(p)
dev.off()
## Bar plot of long term tissue resident in lymph node ###################################################
# Read the data
LN_tr_prop <- read.csv(file = file.path(data_dir, 'LN_tissue_resident_proportions.csv'))
# # Exclude lymphocytes
# LN_tr_prop <- LN_tr_prop[LN_tr_prop$Cell_Type %in% c("CD56 NK", "DN NK", "CD16 NK"),]
# Ensure the order of factors
LN_tr_prop$Cell_Type <- gsub("CD56 NK", "CD56+ NK", LN_tr_prop$Cell_Type)
LN_tr_prop$Cell_Type <- gsub("CD16 NK", "CD16+ NK", LN_tr_prop$Cell_Type)
LN_tr_prop$Cell_Type <- factor(LN_tr_prop$Cell_Type, levels = c("T Cell","CD56+ NK", "DN NK", "CD16+ NK"))
# Calculate stadard deviation
LN_tr_prop_summary <- data_summary_se(LN_tr_prop, varname="tr_percentage",
groupnames=c("Animal", "Cell_Type"))
# Rename colums
colnames(LN_tr_prop_summary)[2] <- "Cell Type"
colnames(LN_tr_prop_summary)[3] <- "value"
# Bar chart with error bars on top
p <- ggplot(LN_tr_prop_summary, aes(x=Animal, y=value, fill=`Cell Type`)) +
geom_bar(stat="identity", color="black", position=position_dodge(), width = 0.75) +
geom_errorbar(aes(ymin=value, ymax=value+se), width=.2,
position=position_dodge(.75)) + theme_classic() +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(1,4,3,2)]) + labs(y = "Percentage Tissue Localized") +
theme(axis.title.x = element_blank(),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
title = element_blank(),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(size = 14, color = "black"), axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_text(size = 14, color = "black", face = "bold"),
legend.text = element_text(size = 14, color = "black"))
pdf(file = file.path(results_dir, "LN_tissue_resident_percentages_with_T.pdf"), width = 10*6/5, height = 4)
plot(p)
dev.off()
## LN tissue residence summary dot plot 6hr ###################################################
# Load means normalized to T cell
means_tr <- read.csv(file = file.path(data_dir, "LN_tissue_resident_proportions_mean_dotplot.csv"))
# Ensure the order of factors
means_tr$Cell_Type <- gsub("CD56 NK", "CD56+ NK", means_tr$Cell_Type)
means_tr$Cell_Type <- gsub("CD16 NK", "CD16+ NK", means_tr$Cell_Type)
means_tr$Cell_Type <- factor(means_tr$Cell_Type, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Box plot with wilcoxon test to compare means
my_comparisons <- list( c("CD56+ NK", "DN NK"), c("DN NK", "CD16+ NK"), c("CD56+ NK", "CD16+ NK") )
p <- ggplot(means_tr, aes(x = Cell_Type, y = value, fill = Cell_Type)) +
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3, coef = 5) +
stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", paired = F,
label.y = c(105, 112.5, 120)) +
geom_point(position=position_jitterdodge(0.1), size = 2.5) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
labs(title = "", y = "Percentage Tissue Localized") +
theme_classic() +
theme(title = element_blank(),
plot.title = element_text(hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
axis.title.x = element_blank(),
axis.text.y = element_text(size = 14, color = "black"),
axis.text.x = element_text(size = 14, color = "black"),
legend.position = "none")+
scale_y_continuous(limits = c(0,125), breaks=seq(0,100,25))
pdf(file = file.path(results_dir, "LN_tissue_residence_boxplot.pdf"), width = 4, height = 4)
plot(p)
dev.off()
## LN Entry rates bar plot 6hr ###################################################
# Read the data
LN_entry_prop <- read.csv(file = file.path(data_dir, 'LN_entry_rate_proportions_6hr.csv'))
# Ensure the order of factors
LN_entry_prop$Cell_Type <- gsub("CD56 NK", "CD56+ NK", LN_entry_prop$Cell_Type)
LN_entry_prop$Cell_Type <- gsub("CD16 NK", "CD16+ NK", LN_entry_prop$Cell_Type)
LN_entry_prop$Cell_Type <- factor(LN_entry_prop$Cell_Type, levels = c("T Cell", "CD56+ NK", "DN NK", "CD16+ NK"))
# Calculate stadard deviation
LN_entry_prop_summary <- data_summary_se(LN_entry_prop, varname="entry_rate_6hr",
groupnames=c("Animal", "Cell_Type"))
# Rename colums
colnames(LN_entry_prop_summary)[2] <- "Cell Type"
colnames(LN_entry_prop_summary)[3] <- "value"
# Bar chart with error bars on top
p <- ggplot(LN_entry_prop_summary, aes(x=Animal, y=value, fill=`Cell Type`)) +
geom_bar(stat="identity", color="black", position=position_dodge(), width = 0.75) +
geom_errorbar(aes(ymin=value, ymax=value+se), width=.2,
position=position_dodge(.75)) + theme_classic() +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(1,4,3,2)]) + labs(y = "Entry Rate into LN (% per Hour)") +
theme(axis.title.x = element_blank(), axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
title = element_blank(),
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(size = 14, color = "black"), axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_text(size = 14, color = "black", face = "bold"), legend.text = element_text(size = 14, color = "black"))
pdf(file = file.path(results_dir, "LN_entry_rates_6hr_with_T.pdf"), width = 10*6/5, height = 4)
plot(p)
dev.off()
## LN Entry rates summary dot plot 6hr ###################################################
# Load means from 6 hour LN entry rates [means from previous plot normalized to lymphocyte percentage]
means_LN_entry <- read.csv(file = file.path(data_dir, "LN_entry_rate_means_dotplot.csv"))
# Ensure the order of factors
means_LN_entry$Cell_Type <- gsub("CD56 NK", "CD56+ NK", means_LN_entry$Cell_Type)
means_LN_entry$Cell_Type <- gsub("CD16 NK", "CD16+ NK", means_LN_entry$Cell_Type)
means_LN_entry$Cell_Type <- factor(means_LN_entry$Cell_Type, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Box plot with wilcoxon test to compare means
my_comparisons <- list( c("CD56+ NK", "DN NK"), c("DN NK", "CD16+ NK"), c("CD56+ NK", "CD16+ NK") )
p <- ggplot(means_LN_entry, aes(x = Cell_Type, y = value, fill = Cell_Type)) +
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3, coef = 5) +
stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", paired = F,
label.y = c(3.5, 3.75, 4)) +
geom_point(position=position_jitterdodge(0.1), size = 2.5) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
labs(title = "", y = "Entry Rate into LN (% per Hour)") +
theme_classic() +
theme(title = element_blank(),
plot.title = element_text(hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
axis.title.x = element_blank(),
axis.text.y = element_text(size = 14, color = "black"),
axis.text.x = element_text(size = 14, color = "black"),
legend.position = "none")
pdf(file = file.path(results_dir, "LN_entry_rate_normalized_boxplot.pdf"), width = 4, height = 4)
plot(p)
dev.off()
## Lymph node summary plot across animals ###################################################
# Read PB data
LN_data <- read.csv(file = file.path(data_dir, 'Summary_data_by_tissue_LN_with_T.csv'))
# Melt into long format
LN_data_long <- reshape2::melt(LN_data, id = c("Animal_Sample","Cell_Type"))
# Ensure the order of my factors
LN_data_long$Animal <- factor(LN_data_long$Animal_Sample, levels = c("DGA0 AxLN", "DGA0 MesLN", "DGF5 AxLN", "G45T AxLN", "G45T IngLN", "TID AxLN"))
LN_data_long$Cell_Type <- gsub("CD56 NK", "CD56+ NK", LN_data_long$Cell_Type)
LN_data_long$Cell_Type <- gsub("CD16 NK", "CD16+ NK", LN_data_long$Cell_Type)
LN_data_long$Cell_Type <- factor(LN_data_long$Cell_Type, levels = c("T Cell", "CD56+ NK", "DN NK", "CD16+ NK"))
# Rename Cell_Type column
colnames(LN_data_long)[2] <- "Cell Type"
# Rename the SIVS variable and ensure order
LN_data_long$variable <- gsub("SIVS_","", as.character(LN_data_long$variable))
LN_data_long$variable <- factor(LN_data_long$variable, levels = c("48hr", "24hr", "6hr", "2hr", "5min"))
LN_data_long$variable <- paste0("-",LN_data_long$variable)
LN_data_long$variable <- factor(LN_data_long$variable, levels = c("-48hr", "-24hr", "-6hr", "-2hr", "-5min"))
LN_data_long <- na.omit(LN_data_long)
# Make bar plot
p <- ggbarplot(LN_data_long, x = "variable", y = "value",
add = c("mean_se", "jitter"),
color = "Cell Type", shape = "Animal", fill = "grey95",
size = 0.8,
palette = brewer.pal(4, name = "Set1")[c(1,4,3,2)],
position = position_dodge(0.8)) +
labs(x = "SIVS Infusion", y = "Percentage SIVS Positive") +
theme(legend.position = "right",
axis.text.x = element_text(size = 14, color = "black"),
axis.text.y = element_text(size = 14, color = "black"),
axis.title.x = element_text(size = 14, color = "black"),
axis.title.y = element_text(size = 14, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),
legend.title = element_text(size = 14, color = "black", face = "bold"),
legend.text = element_text(size = 14, color = "black")) +
guides(
color = guide_legend(order = 1),
shape = guide_legend(order = 0)
)
# Save plot to PDF
pdf(file = file.path(results_dir, "LN_summary_figure_with_T.pdf"), width = 12, height = 5)
plot(p)
dev.off()
## LN Phenotype plot for each animal ###################################################
# Read data
LN_pheno_data <- read.csv(file = file.path(data_dir, "LN_phenotype_data.csv"))
# Loop through each animal
for (my_animal in unique(LN_pheno_data$Animal)){
LN_pheno_my_animal <- LN_pheno_data[LN_pheno_data$Animal == my_animal,]
# Melt the DF
LN_pheno_melt <- melt(LN_pheno_my_animal, id = c("Animal","Tissue"))
# Remove the Ax_LN data
LN_pheno_melt <- LN_pheno_melt[LN_pheno_melt$Tissue %in% c("PB", "IVAS_pos", "IVAS_neg"),]
# Ensure order of factors
LN_pheno_melt$Tissue <- factor(LN_pheno_melt$Tissue, levels = c("PB", "IVAS_pos", "IVAS_neg"))
LN_pheno_melt$variable <- factor(LN_pheno_melt$variable, levels = c("CD56_NK", "DN_NK", "CD16_NK"))
# Make phenotype pie chart for each subset
pheno_plot_list <- list()
mycols <- RColorBrewer::brewer.pal(4, "Set1")
for (i in 1:length(unique(LN_pheno_melt$variable))){
my_tissue <- unique(LN_pheno_melt$Tissue)[i]
plot.data <- LN_pheno_melt[LN_pheno_melt$Tissue == my_tissue,]
# Make pie chart
pheno_plot_list[[i]] <- ggplot(plot.data,
aes(x = "", y = value, fill = variable)) +
geom_bar(width = 1, stat = "identity") +
coord_polar("y", start = 0)+
# geom_text(aes(y = lab.ypos, label = variable), color = "black")+
scale_fill_manual(values = mycols[c(4,3,2)]) +
theme_void() + theme(legend.position = "none")
}
# Make a PDF of the 3 pie charts for each tissue
comb_plot_pheno <- cowplot::plot_grid(plotlist = pheno_plot_list, align = "hv", ncol = 3)
pdf(file = file.path(results_dir, paste(my_animal, "NK_phenotype_pie_chart.pdf", sep = "_")), width = 5*3/2, height = 2.5)
plot(comb_plot_pheno)
dev.off()
}
## LN Phenotype summary plot
# Read data
LN_pheno_data <- read.csv(file = file.path(data_dir, "LN_phenotype_data.csv"))
# Rename tissue variable
LN_pheno_data$Tissue <- plyr::revalue(LN_pheno_data$Tissue, c("PB" = "Blood", "IVAS_pos" = "LN IVas+", "IVAS_neg" = "LN IVas-") )
# Turn data into percentage out of 100
LN_pheno_data[,3:5] <- LN_pheno_data[,3:5] / rowSums(LN_pheno_data[,3:5]) * 100
# Melt
LN_pheno_melt <- reshape2::melt(LN_pheno_data, id = c("Animal","Tissue"))
# Replace _ with space in subset name
LN_pheno_melt$variable <- gsub("_", " ", LN_pheno_melt$variable)
LN_pheno_melt$variable <- gsub("CD56 NK", "CD56+ NK", LN_pheno_melt$variable)
LN_pheno_melt$variable <- gsub("CD16 NK", "CD16+ NK", LN_pheno_melt$variable)
LN_pheno_melt$variable <- factor(LN_pheno_melt$variable, levels = c("CD56+ NK", "DN NK", "CD16+ NK"))
# Keep only the desired data
LN_pheno_melt <- LN_pheno_melt[LN_pheno_melt$Tissue %in% c("Blood", "LN IVas+", "LN IVas-"),]
# Ensure order of factors
LN_pheno_melt$Tissue <- factor(LN_pheno_melt$Tissue, levels = c("Blood", "LN IVas+", "LN IVas-"))
# Set comparisos list for statistics
my_comparisons <- list( c("Blood", "LN IVas+"), c("LN IVas+", "LN IVas-"), c("Blood", "LN IVas-") )
# Box plot with wilcoxon test to compare means
p <- ggplot(LN_pheno_melt, aes(x = Tissue, y = value)) +
facet_wrap(~variable)+
geom_boxplot(color = "black", size = 0.4, outlier.shape = NA, position=position_dodge(0.75), width = 0.6, aes(fill = variable)) +
stat_boxplot(position=position_dodge(0.75), geom = 'errorbar', size = 0.5, width = 0.3, coef = 5) +
stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", paired = F,
label.y = c(100, 107, 114)) +
# geom_point(position=position_jitterdodge(0.1), size = 2.5) +
geom_jitter(size = 2.5, position=position_dodge(0.8)) +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Set1")[c(4,3,2)]) +
scale_y_continuous(trans = "log10") +
labs(title = "", y = "Percentage of NK cells") +
theme_classic() +
theme(title = element_blank(),
plot.title = element_text(hjust = 0.5, margin=margin(0,0,15,0)),
axis.title.y = element_text(size = 12, color = "black", margin = margin(t = 0, r = 10, b = 0, l = 0)),