8
8
# ' @param groupvar_name A character containing the name for the group variable.
9
9
# ' @param group_colours A character vector of hex codes for the group colors.
10
10
# ' @param base_size A numeric containing the base size of the font.
11
+ # ' @param lwd A numeric containing the line width of the boxplot.
12
+ # ' @param outlier_size A numeric containing the size of the outliers.
11
13
# '
12
14
# ' @return a tibble and a ggplot of the valid values
13
15
# ' @export
14
16
# '
15
17
# ' @examples
16
18
# ' \dontrun{
17
19
# ' prepared_data <- prepareData(...)
18
- # '
20
+ # '
19
21
# ' boxplot <- Boxplots(D_long = prepared_data[["D_long"]])
20
22
# ' }
21
- # '
23
+ # '
22
24
23
25
Boxplots <- function (D_long ,
24
- do_log_transformation = FALSE ,
26
+ do_log_transformation = FALSE ,
25
27
log_base = 2 ,
26
28
method = " boxplot" ,
27
29
use_groups = NULL ,
28
- groupvar_name = " Group" ,
30
+ groupvar_name = " Group" ,
29
31
group_colours = NULL ,
30
- base_size = 15 ){
31
-
32
-
32
+ base_size = 15 ,
33
+ lwd = 1 ,
34
+ outlier_size = 1 ){
35
+
36
+
33
37
mess <- " "
34
38
35
39
if (is.null(use_groups )){
@@ -43,45 +47,45 @@ Boxplots <- function(D_long,
43
47
use_groups <- FALSE
44
48
}
45
49
}
46
-
50
+
47
51
# log-transform data if necessary
48
52
if (do_log_transformation ) {
49
53
D_long $ value <- log(D_long $ value , base = log_base )
50
54
}
51
-
55
+
52
56
x_axis <- sort(unique(D_long $ name )) # save the different states for later
53
57
D_long <- D_long [! is.na(D_long $ value ),] # remove NA values
54
-
58
+
55
59
name <- value <- group <- NULL
56
60
if (use_groups ) {
57
61
pl_boxplot <- ggplot2 :: ggplot(D_long , ggplot2 :: aes(x = name , y = value , fill = group )) +
58
- ggplot2 :: labs(fill = groupvar_name )
62
+ ggplot2 :: labs(fill = groupvar_name )
59
63
if (! is.null(group_colours )) pl_boxplot <- pl_boxplot + ggplot2 :: scale_fill_manual(values = group_colours )
60
64
mess <- paste0(mess , " with groups. \n " )
61
65
} else {
62
66
pl_boxplot <- ggplot2 :: ggplot(D_long , ggplot2 :: aes(x = name , y = value ))
63
67
mess <- paste0(mess , " without groups. \n " )
64
68
}
65
-
66
-
69
+
70
+
67
71
pl_boxplot <- pl_boxplot +
68
72
ggplot2 :: theme_bw(base_size = base_size ) +
69
73
ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(angle = 45 , vjust = 1 , hjust = 1 )) +
70
- ggplot2 :: ylab(" Log intensity" ) + ggplot2 :: xlab(" Sample" ) +
74
+ ggplot2 :: ylab(" Log intensity" ) + ggplot2 :: xlab(" Sample" ) +
71
75
ggplot2 :: scale_x_discrete(limits = x_axis , drop = FALSE , na.translate = TRUE )
72
-
73
-
76
+
77
+
74
78
if (method == " violinplot" ){
75
79
pl_boxplot <- pl_boxplot + ggplot2 :: geom_violin()
76
80
mess <- paste0(" Violin Plot generated " , mess )
77
81
}
78
-
82
+
79
83
if (method == " boxplot" ) {
80
- pl_boxplot <- pl_boxplot + ggplot2 :: geom_boxplot()
84
+ pl_boxplot <- pl_boxplot + ggplot2 :: geom_boxplot(linewidth = lwd , outlier.size = outlier_size )
81
85
mess <- paste0(" Boxplot generated " , mess )
82
86
}
83
-
87
+
84
88
message(mess )
85
-
89
+
86
90
return (list (" plot" = pl_boxplot , " message" = mess ))
87
- }
91
+ }
0 commit comments