-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVizVolcano.R
1247 lines (1124 loc) · 63.9 KB
/
VizVolcano.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 name: Visualization
##
## Purpose of script: Data Visualisation of the MetaProViz analysis to aid biological interpretation
##
## Author: Dimitrios Prymidis and Christina Schmidt
##
## Date Created: 2022-10-28
##
## Copyright (c) Dimitrios Prymidis and Christina Schmidt
## Email:
##
## ---------------------------
##
## Notes:
##
##
## ---------------------------
#'
#' This script allows you to perform different data visualizations using the results of the MetaProViz analysis
#####################################
### ### ### Volcano Plots ### ### ###
#####################################
#' Volcano plot visualization
#'
#' @param PlotSettings \emph{Optional: } Choose between "Standard" (InputData), "Compare" (plot two comparisons together InputData and InputData2) or "PEA" (Pathway Enrichment Analysis) \strong{Default = "Standard"}
#' @param SettingsInfo \emph{Optional: } NULL or Named vector including at least one of those three information for Settings="Standard" or "Compare": c(color ="ColumnName_SettingsFile_Metab", shape = "ColumnName_SettingsFile_Metab", individual="ColumnName_SettingsFile_Metab"). For Settings="PEA" a named vector with: PEA_Pathway="ColumnName_InputData2"=each pathway will be plotted, PEA_score="ColumnName_InputData2", PEA_stat= "ColumnName_InputData2"= usually p.adj column, "PEA_Feature="ColumnName_InputData2"= usually Metabolites), optionally you can additionally include c(color_Metab="ColumnName_SettingsFile_Metab", shape= "ColumnName_SettingsFile_Metab").\strong{Default = NULL}
#' @param SettingsFile_Metab \emph{Optional: } DF with column including the Metabolite names (needs to match Metabolite names and Metabolite column name of InputData) and other columns with required PlotSettingInfo. \strong{Default = NULL}
#' @param InputData DF with metabolites as row names and columns including Log2FC and stat (p-value, p.adjusted) value columns.
#' @param InputData2 \emph{Optional: } DF to compare to main Input_data with the same column names x and y (Settings="Compare") and metabolites as row names or Pathway enrichment analysis results (Settings="PEA"). \strong{Default = NULL}
#' @param y \emph{Optional: } Column name including the values that should be used for y-axis. Usually this would include the p.adjusted value. \strong{Default = "p.adj"}
#' @param x \emph{Optional: } Column name including the values that should be used for x-axis. Usually this would include the Log2FC value. \strong{Default = "Log2FC"}
#' @param PlotName \emph{Optional: } String which is added to the output files of the plot. \strong{Default = ""}
#' @param ComparisonName \emph{Optional: } Named vector including those information about the two datasets that are compared on the plots when choosing Settings= "Compare". \strong{Default = c(InputData="Cond1", InputData2= "Cond2")}
#' @param xlab \emph{Optional: } String to replace x-axis label in plot. \strong{Default = NULL}
#' @param ylab \emph{Optional: } String to replace y-axis label in plot. \strong{Default = NULL}
#' @param xCutoff \emph{Optional: } Number of the desired log fold change cutoff for assessing significance. \strong{Default = 0.5}
#' @param yCutoff \emph{Optional: } Number of the desired p value cutoff for assessing significance. \strong{Default = 0.05}
#' @param ColorPalette \emph{Optional: } Provide customiced color-palette in vector format. \strong{Default = NULL}
#' @param ShapePalette \emph{Optional: } Provide customiced shape-palette in vector format. \strong{Default = NULL}
#' @param SelectLab \emph{Optional: } If set to NULL, feature labels will be plotted randomly. If vector is provided, e.g. c("MetaboliteName1", "MetaboliteName2"), selected names will be plotted. If set to default "", no feature names will be plotted. \strong{Default = ""}
#' @param Connectors \emph{Optional: } TRUE or FALSE for whether Connectors from names to points are to be added to the plot. \strong{Default = FALSE}
#' @param Subtitle \emph{Optional: } \strong{Default = ""}
#' @param Theme \emph{Optional: } Selection of theme for plot, e.g. theme_grey(). You can check for complete themes here: https://ggplot2.tidyverse.org/reference/ggtheme.html. \strong{Default = NULL}
#' @param FolderPath {Optional:} Path to the folder the results should be saved at. \strong{default: NULL}
#' @param Features \emph{Optional: } Name of the features that are plotted, e.g. "Metabolites", "RNA", "Proteins", "Genes", etc. \strong{Default = "metabolites"}
#' @param SaveAs_Plot \emph{Optional: } Select the file type of output plots. Options are svg, pdf, png or NULL. \strong{Default = "svg"}
#' @param PrintPlot \emph{Optional: } print the plots to the active graphic
#' device.
#'
#' @return List with two elements: Plot and Plot_Sized
#'
#' @examples
#' Intra <- MetaProViz::ToyData("IntraCells_DMA")
#' Res <- MetaProViz::VizVolcano(InputData=Intra)
#'
#' @keywords Volcano plot, pathways
#'
#' @importFrom ggplot2 ggplot theme
#' @importFrom dplyr rename filter mutate rename_with
#' @importFrom magrittr %>% %<>%
#' @importFrom tibble rownames_to_column column_to_rownames remove_rownames
#' @importFrom logger log_trace
#' @importFrom tidyselect all_of
#'
#' @export
#'
VizVolcano <- function(PlotSettings="Standard",
InputData,
SettingsInfo= NULL,
SettingsFile_Metab=NULL,
InputData2= NULL,
y= "p.adj",
x= "Log2FC",
xlab= NULL,#"~Log[2]~FC"
ylab= NULL,#"~-Log[10]~p.adj"
xCutoff= 0.5,
yCutoff= 0.05,
Connectors= FALSE,
SelectLab= "",
PlotName= "",
Subtitle= "",
ComparisonName= c(InputData="Cond1", InputData2= "Cond2"),
ColorPalette= NULL,
ShapePalette=NULL,
Theme= NULL,
SaveAs_Plot= "svg",
FolderPath = NULL,
Features="Metabolites",
PrintPlot=TRUE){
## ------------ Create log file ----------- ##
MetaProViz_Init()
## ------------ Check Input files ----------- ##
# HelperFunction `CheckInput`
if(PlotSettings=="PEA"){
#Those relationships are checked in the VizVolcano_PEA() function!
SettingsFile <- NULL # For PEA the SettingsFile_Metab is the prior knowledge file, and hence this will not have features as row names.
Info <- NULL # If SettingsFileMetab=NULL, SetingsInfo has to be NULL to, otherwise we will get an error.
}else{
SettingsFile <-SettingsFile_Metab
Info <- SettingsInfo
}
CheckInput(InputData=as.data.frame(t(InputData)),
InputData_Num=FALSE,
SettingsFile_Sample=NULL,
SettingsFile_Metab=SettingsFile,#Set above
SettingsInfo=Info,#Set above
SaveAs_Plot=SaveAs_Plot,
SaveAs_Table=NULL,
CoRe=FALSE,
PrintPlot= PrintPlot,
PlotSettings="Feature")
# CheckInput` Specific:
if(is.numeric(yCutoff)== FALSE |yCutoff > 1 | yCutoff < 0){
message<- paste0("Check input. The selected yCutoff value should be numeric and between 0 and 1.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
if(is.numeric(xCutoff)== FALSE | xCutoff < 0){
message<- paste0("Check input. The selected xCutoff value should be numeric and between 0 and +oo.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
if(paste(x) %in% colnames(InputData)==FALSE | paste(y) %in% colnames(InputData)==FALSE){
message<- paste0("Check your input. The column name of x and/ore y does not exist in Input_data.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
if(is.null(SelectLab)==FALSE & is.vector(SelectLab)==FALSE){
message<- paste0("Check input. SelectLab must be either NULL or a vector.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
if(is.logical(Connectors) == FALSE){
message<- paste0("Check input. The Connectors value should be either = TRUE if connectors from names to points are to be added to the plot or =FALSE if not.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
if(is.null(PlotName)==FALSE & is.vector(PlotName)==FALSE){
message<- paste0("Check input. PlotName must be either NULL or a vector.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
Plot_options <- c("Standard", "Compare", "PEA")
if (PlotSettings %in% Plot_options == FALSE){
message<- paste0("PlotSettings option is incorrect. The allowed options are the following: ",paste(Plot_options, collapse = ", "),"." )
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
## ------------ Create Results output folder ----------- ##
if(is.null(SaveAs_Plot)==FALSE){
Folder <- SavePath(FolderName= "VolcanoPlots",
FolderPath=FolderPath)
}
############################################################################################################
## ----------- Prepare InputData ------------ ##
#Extract required columns and merge with SettingsFile
if(is.null(SettingsFile_Metab)==FALSE){
##--- Prepare the color scheme:
if("color" %in% names(SettingsInfo)==TRUE & "shape" %in% names(SettingsInfo)==TRUE){
if((SettingsInfo[["shape"]] == SettingsInfo[["color"]])==TRUE){
SettingsFile_Metab$shape <- SettingsFile_Metab[,paste(SettingsInfo[["color"]])]
SettingsFile_Metab<- SettingsFile_Metab%>%
dplyr::rename("color"=paste(SettingsInfo[["color"]]))
}else{
SettingsFile_Metab <- SettingsFile_Metab%>%
dplyr::rename("color"=paste(SettingsInfo[["color"]]),
"shape"=paste(SettingsInfo[["shape"]]))
}
}else if("color" %in% names(SettingsInfo)==TRUE & "shape" %in% names(SettingsInfo)==FALSE){
SettingsFile_Metab <- SettingsFile_Metab%>%
dplyr::rename("color"=paste(SettingsInfo[["color"]]))
}else if("color" %in% names(SettingsInfo)==FALSE & "shape" %in% names(SettingsInfo)==TRUE){
SettingsFile_Metab <- SettingsFile_Metab%>%
dplyr::rename("shape"=paste(SettingsInfo[["shape"]]))
}
if("individual" %in% names(SettingsInfo)==TRUE){
SettingsFile_Metab <- SettingsFile_Metab%>%
dplyr::rename("individual"=paste(SettingsInfo[["individual"]]))
}
##--- Merge InputData with SettingsFile:
common_columns <- character(0) # Initialize an empty character vector
for(col_name in colnames(InputData[, c(x, y)])) {
if(col_name %in% colnames(SettingsFile_Metab)) {
common_columns <- c(common_columns, col_name) # Add the common column name to the vector
}
}
if (length(common_columns)) {
SettingsFile_Metab %<>% # rename those column since they otherwise
# will cause issues when we merge the DFs
# later
# this should not be handled like this, use suffixes for dplyr::join
# instead
dplyr::rename_with(
~paste0(.x, "_SettingsFile_Metab"),
tidyselect::all_of(common_columns)
)
}
if(PlotSettings=="PEA"){
VolcanoData <- merge(x=SettingsFile_Metab ,y=InputData[, c(x, y)], by.x=SettingsInfo[["PEA_Feature"]] , by.y=0, all.y=TRUE)%>%
tibble::remove_rownames()%>%
dplyr::mutate(FeatureNames = SettingsInfo[["PEA_Feature"]])%>%
dplyr::filter(!is.na(x) | !is.na(x))
}else{
VolcanoData <- merge(x=SettingsFile_Metab ,y=InputData[, c(x, y)], by=0, all.y=TRUE)%>%
tibble::remove_rownames()%>%
tibble::column_to_rownames("Row.names")%>%
dplyr::mutate(FeatureNames = rownames(InputData))%>%
dplyr::filter(!is.na(x) | !is.na(x))
}
}else{
VolcanoData <- InputData[, c(x, y)]%>%
dplyr::mutate(FeatureNames = rownames(InputData))%>%
dplyr::filter(!is.na(x) | !is.na(x))
}
# Rename the x and y lab if the information has been passed:
if(is.null(xlab)==TRUE){#use column name of x provided by user
xlab <- bquote(.(as.symbol(x)))
}else if(is.null(xlab)==FALSE){
xlab <- bquote(.(as.symbol(xlab)))
}
if(is.null(ylab)==TRUE){#use column name of x provided by user
ylab <- bquote(.(as.symbol(y)))
}else if(is.null(ylab)==FALSE){
ylab <- bquote(.(as.symbol(ylab)))
}
## ----------- Set the plot parameters: ------------ ##
##--- Prepare colour and shape palette
if(is.null(ColorPalette)){
if("color" %in% names(SettingsInfo)==TRUE){
safe_colorblind_palette <- c("#88CCEE", "#DDCC77","#661100", "#332288", "#AA4499","#999933", "#44AA99", "#882215", "#6699CC", "#117733", "#888888","#CC6677", "black","gold1","darkorchid4","red","orange", "blue")
}else{
safe_colorblind_palette <- c("#888888", "#44AA99", "#44AA99","#CC6677")
}
#check that length is enough for what the user wants to colour
#stop(" The maximum number of pathways in the Input_pathways must be less than ",length(safe_colorblind_palette),". Please summarize sub-pathways together where possible and repeat.")
} else{
safe_colorblind_palette <-ColorPalette
#check that length is enough for what the user wants to colour
}
if(is.null(ShapePalette)){
safe_shape_palette <- c(15,17,16,18,25,7,8,11,12)
#check that length is enough for what the user wants to shape
} else{
safe_shape_palette <-shape_palette
#check that length is enough for what the user wants to shape
}
############################################################################################################
## ----------- Make the plot based on the chosen parameters ------------ ##
if(PlotSettings=="Standard"){#####--- 1. Standard
VolcanoRes <- VizVolcano_Standard(InputData= VolcanoData,
SettingsFile_Metab=SettingsFile_Metab,
SettingsInfo=SettingsInfo,
y= y,
x= x,
xlab= xlab,
ylab= ylab,
xCutoff= xCutoff,
yCutoff= yCutoff,
Connectors= Connectors,
SelectLab=SelectLab,
PlotName= PlotName,
Subtitle= Subtitle,
ColorPalette=safe_colorblind_palette,
ShapePalette=safe_shape_palette,
Theme= Theme,
Features=Features,
SaveAs_Plot=SaveAs_Plot,
PrintPlot=PrintPlot,
Folder=Folder)
}else if(PlotSettings=="Compare"){#####--- 2. Compare
VolcanoRes <- VizVolcano_Compare(InputData= VolcanoData,
InputData2=InputData2,
SettingsFile_Metab=SettingsFile_Metab,
SettingsInfo=SettingsInfo,
y= y,
x= x,
xlab= xlab,
ylab= ylab,
xCutoff= xCutoff,
yCutoff= yCutoff,
Connectors= Connectors,
SelectLab=SelectLab,
PlotName= PlotName,
Subtitle= Subtitle,
ColorPalette=safe_colorblind_palette,
ShapePalette=safe_shape_palette,
Theme= Theme,
Features=Features,
ComparisonName=ComparisonName,
SaveAs_Plot=SaveAs_Plot,
PrintPlot=PrintPlot,
Folder=Folder)
} else if(PlotSettings=="PEA"){#####--- 3. PEA
VolcanoRes <- VizVolcano_PEA(InputData= VolcanoData,
InputData2=InputData2,
SettingsFile_Metab=SettingsFile_Metab,#Problem: we need to know the column name of the features!
SettingsInfo=SettingsInfo,
y= y,
x= x,
xlab= xlab,
ylab= ylab,
xCutoff= xCutoff,
yCutoff= yCutoff,
Connectors= Connectors,
SelectLab=SelectLab,
PlotName= PlotName,
Subtitle= Subtitle,
ColorPalette=safe_colorblind_palette,
ShapePalette=safe_shape_palette,
Theme= Theme,
Features=Features,
SaveAs_Plot=SaveAs_Plot,
PrintPlot=PrintPlot,
Folder=Folder)
}
return(invisible(VolcanoRes))
}
################################################################################################
### ### ### VizVolcano helper function: Internal Function for PlotSettings Standard ### ### ###
################################################################################################
#' VizVolcano_Standard
#'
#' @param InputData Passed to main function VizVolcano()
#' @param SettingsFile_Metab Passed to main function VizVolcano()
#' @param SettingsInfo Passed to main function VizVolcano()
#' @param y \emph{Optional: } Passed to main function VizVolcano() \strong{Default = "p.adj"}
#' @param x \emph{Optional: } Passed to main function VizVolcano() \strong{Default = "Log2FC"}
#' @param PlotName \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param xlab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = NULL}
#' @param ylab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = NULL}
#' @param xCutoff \emph{Optional: } Passed to main function VizVolcano() \strong{Default = 0.5}
#' @param ycutoff \emph{Optional: } Passed to main function VizVolcano() \strong{Default = 0.05}
#' @param SelectLab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param Connectors \emph{Optional: } Passed to main function VizVolcano() \strong{Default = FALSE}
#' @param Subtitle \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param ColorPalette Created in VizVolcano() based on ColorPalette passed to main function VizVolcano()
#' @param ShapePalette Created in VizVolcano() based on ShapePalette passed to main function VizVolcano()
#' @param Theme \emph{Optional: } Selection of theme for plot, e.g. theme_grey(). You can check for complete themes here: https://ggplot2.tidyverse.org/reference/ggtheme.html. \strong{Default = NULL}
#' @param Features \emph{Optional: } Name of the features that are plotted, e.g. "Metabolites", "RNA", "Proteins", "Genes", etc. \strong{Default = "Metabolites"}
#' @param SaveAs_Plot Passed to main function VizVolcano()
#' @param PrintPlot Passed to main function VizVolcano()
#' @param Folder Created in VizVolcano(). Path to the folder where files are saved.
#'
#' @return List with two elements: Plot and Plot_Sized
#'
#' @keywords Standard volcano plots
#'
#' @importFrom ggplot2 ggplot theme
#' @importFrom dplyr rename filter mutate
#' @importFrom magrittr %>% %<>%
#' @importFrom tibble rownames_to_column column_to_rownames remove_rownames
#'
#' @noRd
#'
VizVolcano_Standard <- function(InputData,
SettingsFile_Metab,
SettingsInfo,
y= "p.adj",
x= "Log2FC",
xlab= NULL,#"~Log[2]~FC"
ylab= NULL,#"~-Log[10]~p.adj"
xCutoff= 0.5,
yCutoff= 0.05,
Connectors= FALSE,
SelectLab= "",
PlotName= "",
Subtitle= "",
ColorPalette,
ShapePalette,
Theme= NULL,
Features="Metabolites",
SaveAs_Plot,
PrintPlot,
Folder){
#Pass colours/shapes
safe_colorblind_palette <- ColorPalette
safe_shape_palette <- ShapePalette
#Plots
if("individual" %in% names(SettingsInfo)==TRUE){
# Create the list of individual plots that should be made:
IndividualPlots <- unique(InputData$individual)
PlotList <- list()#Empty list to store all the plots
PlotList_adaptedGrid <- list()#Empty list to store all the plots
for (i in IndividualPlots){
InputVolcano <- subset(InputData, individual == paste(i))
if(nrow(InputVolcano)>=1){
if("color" %in% names(SettingsInfo)==TRUE ){
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$color))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$color) %in% InputVolcano[row, "color"]]
names(col) <- InputVolcano$color[row]
keyvals <- c(keyvals, col)
}
LegendPos<- "right"
} else{
keyvals <-NULL
}
#Prepare the shape scheme:
if("shape" %in% names(SettingsInfo)==TRUE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$shape))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$shape) %in% InputVolcano[row, "shape"]]
names(sha) <- InputVolcano$shape[row]
keyvalsshape <- c(keyvalsshape, sha)
}
LegendPos<- "right"
} else{
keyvalsshape <-NULL
}
if("color" %in% names(SettingsInfo)==FALSE & "shape" %in% names(SettingsInfo)==FALSE){
LegendPos<- "none"
}
#Prepare the Plot:
Plot<- EnhancedVolcano::EnhancedVolcano(InputVolcano,
lab = InputVolcano$FeatureNames,#Metabolite name
selectLab = SelectLab,
x = paste(x),
y = paste(y),
xlab =xlab,
ylab =ylab,
pCutoff = yCutoff,
FCcutoff = xCutoff,#Cut off Log2FC, automatically 2
pointSize = 3,
labSize = 3,
axisLabSize = 10,
titleLabSize = 12,
subtitleLabSize = 11,
captionLabSize = 10,
col=safe_colorblind_palette,
colCustom = keyvals,
shapeCustom = keyvalsshape,
colAlpha = 1,
title= paste(PlotName, ": ", i, sep=""),
subtitle = Subtitle,
caption = paste0("Total = ", nrow(InputVolcano), " ", Features),
xlim = c(min(InputVolcano[[x]][is.finite(InputVolcano[[x]] )])-0.2, max(InputVolcano[[x]][is.finite(InputVolcano[[x]])])+1.2),
ylim = c(0,(ceiling(-log10(Reduce(min,InputVolcano[[y]]))))),
cutoffLineType = "dashed",
cutoffLineCol = "black",
cutoffLineWidth = 0.5,
legendLabels=c(paste(x," < |", xCutoff, "|"), paste(x," > |", xCutoff, "|"), paste(y, ' < ', yCutoff) , paste(y, ' < ', yCutoff,' & ',x," < |", xCutoff, "|")),
legendPosition = LegendPos,
legendLabSize = 7,
legendIconSize =4,
gridlines.major = FALSE,
gridlines.minor = FALSE,
drawConnectors = Connectors)
#Add the theme
if(is.null(Theme)==FALSE){
Plot <- Plot+Theme
}
## Store the plot in the 'plots' list
PlotList[[i]] <- Plot
#Set the total heights and widths
PlotTitle <- paste(PlotName, ": ", i, sep="")
Plot_Sized <- plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotTitle, Subtitle = Subtitle)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = ggplot2::element_rect(fill = "transparent")))
cleaned_i <- gsub("[[:space:],/\\\\]", "-", i)#removes empty spaces and replaces /,\ with -
PlotList_adaptedGrid[[cleaned_i]] <- Plot_Sized
SaveList <- list()
SaveList[[cleaned_i]] <- Plot_Sized
#----- Save
suppressMessages(suppressWarnings(
SaveRes(InputList_DF=NULL,
InputList_Plot= SaveList,
SaveAs_Table=NULL,
SaveAs_Plot=SaveAs_Plot,
FolderPath= Folder,
FileName= paste("Volcano_",PlotName, sep=""),
CoRe=FALSE,
PrintPlot=PrintPlot,
PlotHeight= PlotHeight,
PlotWidth=PlotWidth,
PlotUnit="cm")))
}
}
}else if("individual" %in% names(SettingsInfo)==FALSE){
PlotList <- list()#Empty list to store all the plots
PlotList_adaptedGrid <- list()#Empty list to store all the plots
InputVolcano <- InputData
if(nrow(InputVolcano)>=1){
if("color" %in% names(SettingsInfo)==TRUE ){
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$color))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$color) %in% InputVolcano[row, "color"]]
names(col) <- InputVolcano$color[row]
keyvals <- c(keyvals, col)
}
LegendPos<- "right"
} else{
keyvals <-NULL
}
#Prepare the shape scheme:
if("shape" %in% names(SettingsInfo)==TRUE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$shape))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$shape) %in% InputVolcano[row, "shape"]]
names(sha) <- InputVolcano$shape[row]
keyvalsshape <- c(keyvalsshape, sha)
}
LegendPos<- "right"
} else{
keyvalsshape <-NULL
}
if("color" %in% names(SettingsInfo)==FALSE & "shape" %in% names(SettingsInfo)==FALSE){
LegendPos<- "none"
}
#Prepare the Plot:
Plot<- EnhancedVolcano::EnhancedVolcano(InputVolcano,
lab = InputVolcano$FeatureNames,#Metabolite name
selectLab = SelectLab,
x = paste(x),
y = paste(y),
xlab =xlab,
ylab =ylab,
pCutoff = yCutoff,
FCcutoff = xCutoff,#Cut off Log2FC, automatically 2
pointSize = 3,
labSize = 3,
axisLabSize = 10,
titleLabSize = 12,
subtitleLabSize = 11,
captionLabSize = 10,
col=safe_colorblind_palette,
colCustom = keyvals,
shapeCustom = keyvalsshape,
colAlpha = 1,
title= paste(PlotName),
subtitle = Subtitle,
caption = paste0("Total = ", nrow(InputVolcano), " ", Features),
xlim = c(min(InputVolcano[[x]][is.finite(InputVolcano[[x]] )])-0.2, max(InputVolcano[[x]][is.finite(InputVolcano[[x]])])+1.2),
ylim = c(0,(ceiling(-log10(Reduce(min,InputVolcano[[y]]))))),
cutoffLineType = "dashed",
cutoffLineCol = "black",
cutoffLineWidth = 0.5,
legendLabels=c(paste(x," < |", xCutoff, "|"), paste(x," > |", xCutoff, "|"), paste(y, ' < ', yCutoff) , paste(y, ' < ', yCutoff,' & ',x," < |", xCutoff, "|")),
legendPosition = LegendPos,
legendLabSize = 9,
legendIconSize =4,
gridlines.major = FALSE,
gridlines.minor = FALSE,
drawConnectors = Connectors)
#Add the theme
if(is.null(Theme)==FALSE){
Plot <- Plot+Theme
}
## Store the plot in the 'plots' list
PlotList[["Plot"]] <- Plot
#Set the total heights and widths
Plot_Sized <- plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotName, Subtitle = Subtitle)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = ggplot2::element_rect(fill = "transparent")))
PlotList_adaptedGrid[["Plot_Sized"]] <- Plot_Sized
#----- Save
suppressMessages(suppressWarnings(
SaveRes(InputList_DF=NULL,
InputList_Plot= list("Plot_Sized"= PlotList_adaptedGrid[["Plot_Sized"]]),
SaveAs_Table=NULL,
SaveAs_Plot=SaveAs_Plot,
FolderPath= Folder,
FileName= paste("Volcano_", PlotName, sep=""),
CoRe=FALSE,
PrintPlot=PrintPlot,
PlotHeight=PlotHeight,
PlotWidth=PlotWidth,
PlotUnit="cm")))
}
}
return(invisible(list("Plot"=PlotList,"Plot_Sized" = PlotList_adaptedGrid)))
}
################################################################################################
### ### ### VizVolcano helper function: Internal Function for PlotSettings Compare ### ### ###
################################################################################################
#' Check input parameters
#'
#' @param InputData Passed to main function VizVolcano()
#' @param InputData2 Passed to main function VizVolcano()
#' @param SettingsFile_Metab Passed to main function VizVolcano()
#' @param SettingsInfo Passed to main function VizVolcano()
#' @param y \emph{Optional: } Passed to main function VizVolcano() \strong{Default = "p.adj"}
#' @param x \emph{Optional: } Passed to main function VizVolcano() \strong{Default = "Log2FC"}
#' @param PlotName \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param xlab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = NULL}
#' @param ylab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = NULL}
#' @param xCutoff \emph{Optional: } Passed to main function VizVolcano() \strong{Default = 0.5}
#' @param ycutoff \emph{Optional: } Passed to main function VizVolcano() \strong{Default = 0.05}
#' @param SelectLab \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param Connectors \emph{Optional: } Passed to main function VizVolcano() \strong{Default = FALSE}
#' @param Subtitle \emph{Optional: } Passed to main function VizVolcano() \strong{Default = ""}
#' @param ColorPalette Created in VizVolcano() based on ColorPalette passed to main function VizVolcano()
#' @param ShapePalette Created in VizVolcano() based on ShapePalette passed to main function VizVolcano()
#' @param Theme \emph{Optional: } Selection of theme for plot, e.g. theme_grey(). You can check for complete themes here: https://ggplot2.tidyverse.org/reference/ggtheme.html. \strong{Default = NULL}
#' @param Features \emph{Optional: } Name of the features that are plotted, e.g. "Metabolites", "RNA", "Proteins", "Genes", etc. \strong{Default = "Metabolites"}
#' @param ComparisonName Passed to main function VizVolcano()
#' @param SaveAs_Plot Passed to main function VizVolcano()
#' @param PrintPlot Passed to main function VizVolcano()
#' @param Folder Created in VizVolcano(). Path to the folder where files are saved.
#'
#' @return List with two elements: Plot and Plot_Sized
#'
#' @keywords Compare volcano plots
#'
#' @importFrom ggplot2 ggplot theme
#' @importFrom dplyr rename filter mutate
#' @importFrom magrittr %>% %<>%
#' @importFrom tibble rownames_to_column column_to_rownames remove_rownames
#' @importFrom logger log_trace
#'
#' @noRd
#'
VizVolcano_Compare <- function(InputData,
InputData2,
SettingsFile_Metab,
SettingsInfo,
y= "p.adj",
x= "Log2FC",
xlab= NULL,#"~Log[2]~FC"
ylab= NULL,#"~-Log[10]~p.adj"
xCutoff= 0.5,
yCutoff= 0.05,
Connectors= FALSE,
SelectLab= "",
PlotName= "",
Subtitle= "",
ColorPalette,
ShapePalette,
Theme= NULL,
Features="Metabolites",
ComparisonName,
SaveAs_Plot,
PrintPlot,
Folder){
#####################
##--- Check InputData
if(is.data.frame(InputData2)==FALSE){
if(paste(x) %in% colnames(InputData2)==FALSE | paste(y) %in% colnames(InputData2)==FALSE){
message <- paste("Check your InputData2. The column name of ", x, " and/or ", y, " does not exist in InputData2.")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
}
if(any(duplicated(row.names(InputData2)))==TRUE){
message <- paste("Duplicated row.names of InputData2, whilst row.names must be unique")
logger::log_trace(paste("Error ", message, sep=""))
stop(message)
}
#Pass colours/shapes
safe_colorblind_palette <- ColorPalette
safe_shape_palette <- ShapePalette
##--- Prepare Input Data
if(is.null(SettingsFile_Metab)==FALSE){
InputData2 <- merge(x=SettingsFile_Metab%>%tibble::rownames_to_column("FeatureNames") , y=InputData2[, c(x, y)]%>%tibble::rownames_to_column("FeatureNames") , by="FeatureNames", all.y=TRUE)%>%
filter(!is.na(x) | !is.na(x))
InputData[,"comparison"] <- as.character(paste(ComparisonName[["InputData"]]))
InputData2[,"comparison"] <- as.character(paste(ComparisonName[["InputData2"]]))
InputCompare <- rbind(InputData,InputData2)
}else{
InputData2 <- InputData2[, c(x, y)]%>%
mutate(FeatureNames = rownames(InputData2))%>%
na.omit()
#Combine DFs and add appropriate column names
InputData[,"comparison"] <- as.character(paste(ComparisonName[["InputData"]]))
InputData2[,"comparison"] <- as.character(paste(ComparisonName[["InputData2"]]))
InputCompare <- rbind(InputData[,c("FeatureNames", x, y, "comparison")],InputData2[,c("FeatureNames", x, y, "comparison")])
}
#####################
##--- Plots
if("individual" %in% names(SettingsInfo)==TRUE){
# Create the list of individual plots that should be made:
IndividualPlots <- unique(InputCompare$individual)
PlotList <- list()#Empty list to store all the plots
PlotList_adaptedGrid <- list()#Empty list to store all the plots
for (i in IndividualPlots){
InputVolcano <- subset(InputCompare, individual == paste(i))
if(nrow(InputVolcano)>=1){
#Prepare the colour scheme:
if("color" %in% names(SettingsInfo)==TRUE){
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$color))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$color) %in% InputVolcano[row, "color"]]
names(col) <- InputVolcano$color[row]
keyvals <- c(keyvals, col)
}
} else{#here we will use the conditions if no other color is provided!
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$comparison))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(col) <- InputVolcano$comparison[row]
keyvals <- c(keyvals, col)
}
}
#Prepare the shape scheme:
if("shape" %in% names(SettingsInfo)==TRUE & "color" %in% names(SettingsInfo)==FALSE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$shape))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$shape) %in% InputVolcano[row, "shape"]]
names(sha) <- InputVolcano$shape[row]
keyvalsshape <- c(keyvalsshape, sha)
}
} else if("shape" %in% names(SettingsInfo)==TRUE & "color" %in% names(SettingsInfo)==TRUE){
#Here we have already used color from SettingsInfo and we need to use shape for the conditions
message("For Plot_setting= `Consitions`we can only use colour or shape from SettingsFile_Metab. We ignore shape and use it to label the Comparison_name.")
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$comparison))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(sha) <- InputVolcano$comparison[row]
keyvalsshape <- c(keyvalsshape, sha)
}
} else if("shape" %in% names(SettingsInfo)==FALSE & "color" %in% names(SettingsInfo)==FALSE | "shape" %in% names(SettingsInfo)==FALSE & "color" %in% names(SettingsInfo)==TRUE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$comparison))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(sha) <- InputVolcano$comparison[row]
keyvalsshape <- c(keyvalsshape, sha)
}
}
#Prepare the Plot:
Plot<- EnhancedVolcano::EnhancedVolcano(InputVolcano,
lab = InputVolcano$FeatureNames,#Metabolite name
selectLab = SelectLab,
x = paste(x),
y = paste(y),
xlab =xlab,
ylab =ylab,
pCutoff = yCutoff,
FCcutoff = xCutoff,#Cut off Log2FC, automatically 2
pointSize = 3,
labSize = 3,
axisLabSize = 10,
titleLabSize = 12,
subtitleLabSize = 11,
captionLabSize = 10,
col=safe_colorblind_palette,
colCustom = keyvals,
shapeCustom = keyvalsshape,
colAlpha = 1,
title= paste(PlotName, ": ", i, sep=""),
subtitle = Subtitle,
caption = paste0("Total = ", (nrow(InputVolcano)/2), " ", Features),
xlim = c(min(InputVolcano[[x]][is.finite(InputVolcano[[x]] )])-0.2, max(InputVolcano[[x]][is.finite(InputVolcano[[x]])])+1.2),
ylim = c(0,(ceiling(-log10(Reduce(min,InputVolcano[[y]]))))),
cutoffLineType = "dashed",
cutoffLineCol = "black",
cutoffLineWidth = 0.5,
legendLabels=c(paste(x," < |", xCutoff, "|"), paste(x," > |", xCutoff, "|"), paste(y, ' < ', yCutoff) , paste(y, ' < ', yCutoff,' & ',x," < |", xCutoff, "|")),
legendPosition = 'right',
legendLabSize = 7,
legendIconSize =4,
gridlines.major = FALSE,
gridlines.minor = FALSE,
drawConnectors = Connectors)
#Add the theme
if(is.null(Theme)==FALSE){
Plot <- Plot+Theme
}
## Store the plot in the 'plots' list
PlotList[[i]] <- Plot
#Set the total heights and widths
PlotTitle <- paste(PlotName, ": ", i, sep="")
Plot_Sized <- plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotTitle, Subtitle = Subtitle)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = ggplot2::element_rect(fill = "transparent")))
cleaned_i <- gsub("[[:space:],/\\\\]", "-", i)#removes empty spaces and replaces /,\ with -
PlotList_adaptedGrid[[cleaned_i]] <- Plot_Sized
SaveList <- list()
SaveList[[cleaned_i]] <- Plot_Sized
#----- Save
suppressMessages(suppressWarnings(
SaveRes(InputList_DF=NULL,
InputList_Plot= SaveList,
SaveAs_Table=NULL,
SaveAs_Plot=SaveAs_Plot,
FolderPath= Folder,
FileName= paste("Volcano_",PlotName, sep=""),
CoRe=FALSE,
PrintPlot=PrintPlot,
PlotHeight=PlotHeight,
PlotWidth=PlotWidth,
PlotUnit="cm")))
}
}
} else if("individual" %in% names(SettingsInfo)==FALSE){
PlotList <- list()#Empty list to store all the plots
PlotList_adaptedGrid <- list()#Empty list to store all the plots
if(nrow(InputCompare)>=1){
InputVolcano <- InputCompare
#Prepare the colour scheme:
if("color" %in% names(SettingsInfo)==TRUE){
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$color))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$color) %in% InputVolcano[row, "color"]]
names(col) <- InputVolcano$color[row]
keyvals <- c(keyvals, col)
}
} else{#here we will use the conditions if no other color is provided!
color_select <- safe_colorblind_palette[1:length(unique(InputVolcano$comparison))]
keyvals <- c()
for(row in 1:nrow(InputVolcano)){
col <- color_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(col) <- InputVolcano$comparison[row]
keyvals <- c(keyvals, col)
}
}
#Prepare the shape scheme:
if("shape" %in% names(SettingsInfo)==TRUE & "color" %in% names(SettingsInfo)==FALSE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$shape))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$shape) %in% InputVolcano[row, "shape"]]
names(sha) <- InputVolcano$shape[row]
keyvalsshape <- c(keyvalsshape, sha)
}
} else if("shape" %in% names(SettingsInfo)==TRUE & "color" %in% names(SettingsInfo)==TRUE){
#Here we have already used color from SettingsInfo and we need to use shape for the conditions
message("For PlotSettings Comparison we can only use colour or shape from SettingsFile_Metab. Hence, we ignore shape and use it to label the ComparisonName.")
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$comparison))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(sha) <- InputVolcano$comparison[row]
keyvalsshape <- c(keyvalsshape, sha)
}
} else if("shape" %in% names(SettingsInfo)==FALSE & "color" %in% names(SettingsInfo)==FALSE | "shape" %in% names(SettingsInfo)==FALSE & "color" %in% names(SettingsInfo)==TRUE){
shape_select <- safe_shape_palette[1:length(unique(InputVolcano$comparison))]
keyvalsshape <- c()
for(row in 1:nrow(InputVolcano)){
sha <- shape_select[unique(InputVolcano$comparison) %in% InputVolcano[row, "comparison"]]
names(sha) <- InputVolcano$comparison[row]
keyvalsshape <- c(keyvalsshape, sha)
}
}
#Prepare the Plot:
Plot<- EnhancedVolcano::EnhancedVolcano(InputVolcano,
lab = InputVolcano$FeatureNames,#Metabolite name
selectLab = SelectLab,
x = paste(x),
y = paste(y),
xlab =xlab,
ylab =ylab,
pCutoff = yCutoff,
FCcutoff = xCutoff,#Cut off Log2FC, automatically 2
pointSize = 3,
labSize = 3,
axisLabSize = 10,
titleLabSize = 12,
subtitleLabSize = 11,
captionLabSize = 10,
col=safe_colorblind_palette,
colCustom = keyvals,
shapeCustom = keyvalsshape,
colAlpha = 1,
title= paste(PlotName),
subtitle = Subtitle,
caption = paste0("Total = ", (nrow(InputVolcano)/2)," ", Features),
xlim = c(min(InputVolcano[[x]][is.finite(InputVolcano[[x]] )])-0.2, max(InputVolcano[[x]][is.finite(InputVolcano[[x]])])+1.2),
ylim = c(0,(ceiling(-log10(Reduce(min,InputVolcano[[y]]))))),
cutoffLineType = "dashed",
cutoffLineCol = "black",
cutoffLineWidth = 0.5,
legendLabels=c(paste(x," < |", xCutoff, "|"), paste(x," > |", xCutoff, "|"), paste(y, ' < ', yCutoff) , paste(y, ' < ', yCutoff,' & ',x," < |", xCutoff, "|")),
legendPosition = 'right',
legendLabSize = 7,
legendIconSize =4,
gridlines.major = FALSE,
gridlines.minor = FALSE,
drawConnectors = Connectors)
#Add the theme
if(is.null(Theme)==FALSE){
Plot <- Plot+Theme
}
## Store the plot in the 'plots' list
PlotList[["Plot"]] <- Plot
Plot_Sized <- plotGrob_Volcano(InputPlot=Plot, SettingsInfo=SettingsInfo, PlotName = PlotName, Subtitle = Subtitle)
PlotHeight <- grid::convertUnit(Plot_Sized$height, 'cm', valueOnly = TRUE)
PlotWidth <- grid::convertUnit(Plot_Sized$width, 'cm', valueOnly = TRUE)
Plot_Sized %<>%
{ggplot2::ggplot() + annotation_custom(.)} %>%
add(theme(panel.background = ggplot2::element_rect(fill = "transparent")))
PlotList_adaptedGrid[["Plot_Sized"]] <- Plot_Sized
#----- Save
suppressMessages(suppressWarnings(
SaveRes(InputList_DF=NULL,
InputList_Plot= list("Plot_Sized"= PlotList_adaptedGrid[["Plot_Sized"]]),
SaveAs_Table=NULL,
SaveAs_Plot=SaveAs_Plot,