Skip to content

Commit 1a027f3

Browse files
author
Karin Schork
committed
allow changes in size of lines and outliers in the boxplot
1 parent 0ac8d1f commit 1a027f3

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

R/Boxplot.R

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,32 @@
88
#' @param groupvar_name A character containing the name for the group variable.
99
#' @param group_colours A character vector of hex codes for the group colors.
1010
#' @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.
1113
#'
1214
#' @return a tibble and a ggplot of the valid values
1315
#' @export
1416
#'
1517
#' @examples
1618
#' \dontrun{
1719
#' prepared_data <- prepareData(...)
18-
#'
20+
#'
1921
#' boxplot <- Boxplots(D_long = prepared_data[["D_long"]])
2022
#' }
21-
#'
23+
#'
2224

2325
Boxplots <- function(D_long,
24-
do_log_transformation = FALSE,
26+
do_log_transformation = FALSE,
2527
log_base = 2,
2628
method = "boxplot",
2729
use_groups = NULL,
28-
groupvar_name = "Group",
30+
groupvar_name = "Group",
2931
group_colours = NULL,
30-
base_size = 15){
31-
32-
32+
base_size = 15,
33+
lwd = 1,
34+
outlier_size = 1){
35+
36+
3337
mess <- ""
3438

3539
if(is.null(use_groups)){
@@ -43,45 +47,45 @@ Boxplots <- function(D_long,
4347
use_groups <- FALSE
4448
}
4549
}
46-
50+
4751
# log-transform data if necessary
4852
if(do_log_transformation) {
4953
D_long$value <- log(D_long$value, base = log_base)
5054
}
51-
55+
5256
x_axis <- sort(unique(D_long$name)) # save the different states for later
5357
D_long <- D_long[!is.na(D_long$value),] # remove NA values
54-
58+
5559
name <- value <- group <- NULL
5660
if (use_groups) {
5761
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)
5963
if (!is.null(group_colours)) pl_boxplot <- pl_boxplot + ggplot2::scale_fill_manual(values = group_colours)
6064
mess <- paste0(mess, "with groups. \n")
6165
} else {
6266
pl_boxplot <- ggplot2::ggplot(D_long, ggplot2::aes(x = name, y = value))
6367
mess <- paste0(mess, "without groups. \n")
6468
}
65-
66-
69+
70+
6771
pl_boxplot <- pl_boxplot +
6872
ggplot2::theme_bw(base_size = base_size) +
6973
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") +
7175
ggplot2::scale_x_discrete(limits = x_axis, drop = FALSE, na.translate = TRUE)
72-
73-
76+
77+
7478
if (method == "violinplot"){
7579
pl_boxplot <- pl_boxplot + ggplot2::geom_violin()
7680
mess <- paste0("Violin Plot generated ", mess)
7781
}
78-
82+
7983
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)
8185
mess <- paste0("Boxplot generated ", mess)
8286
}
83-
87+
8488
message(mess)
85-
89+
8690
return(list("plot" = pl_boxplot, "message" = mess))
87-
}
91+
}

0 commit comments

Comments
 (0)