Skip to content

Commit 02bf0f5

Browse files
committed
add fill_scale to visualize.boxplot
1 parent a8e5270 commit 02bf0f5

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Description: Offers simple tools to manipulate and investigate mass spectrometry
1616
License: GPL-3 + file LICENSE
1717
Depends: R (>= 4.1.0)
1818
Imports:
19+
RColorBrewer,
1920
Rdpack,
2021
UpSetR,
2122
cowplot,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import(limma)
4747
import(pheatmap)
4848
import(tibble)
4949
import(tidyr)
50+
importFrom(RColorBrewer,brewer.pal)
5051
importFrom(Rdpack,reprompt)
5152
importFrom(UpSetR,upset)
5253
importFrom(cowplot,plot_grid)

R/visualizations.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,32 @@ visualize.boxplot <- function(dataSet) {
3737
plotData <- dataSet %>%
3838
pivot_longer(-c(R.Condition, R.Replicate))
3939

40-
ggplot(plotData, aes(x = R.Condition, y = value,
41-
fill = if (length(unique(R.Replicate)) == 1) R.Condition else R.Replicate)) +
40+
if (length(unique(dataSet$R.Replicate)) == 1) {
41+
fill_var <- "R.Condition"
42+
nfill <- length(unique(dataSet$R.Condition))
43+
} else {
44+
fill_var <- "R.Replicate"
45+
nfill <- length(unique(dataSet$R.Replicate))
46+
}
47+
48+
if (nfill <= 11) {
49+
fill_scale <- scale_fill_brewer(palette = "RdYlBu")
50+
} else {
51+
cols <- colorRampPalette(brewer.pal(11, "RdYlBu"))(nfill)
52+
fill_scale <- scale_fill_manual(values = cols)
53+
}
54+
55+
ggplot(plotData, aes(x = R.Condition, y = value, fill = .data[[fill_var]])) +
4256
geom_boxplot(varwidth = TRUE) +
4357
guides(fill = guide_legend(
44-
title = ifelse(length(unique(plotData$R.Replicate)) == 1, "Condition", "Replicate"))) +
58+
title = ifelse(fill_var == "R.Condition", "Condition", "Replicate"))) +
4559
xlab("Condition") +
4660
ylab("Signal value") +
47-
scale_fill_brewer(palette = "RdYlBu") +
61+
fill_scale +
4862
theme_bw() +
49-
theme(legend.position = ifelse(length(unique(plotData$R.Replicate)) == 1, "none", "bottom"),
63+
theme(legend.position = ifelse(fill_var == "R.Condition", "none", "bottom"),
5064
plot.title = element_text(hjust = .5))
51-
65+
5266
}
5367

5468

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#' @import tibble
55
#' @import tidyr
66
#' @importFrom openxlsx write.xlsx
7+
#' @importFrom RColorBrewer brewer.pal
78
#' @importFrom Rdpack reprompt
89
#' @importFrom stats as.formula cor density integrate median model.matrix na.omit p.adjust
910
#' @importFrom stats pnorm prcomp sd setNames t.test wilcox.test var

0 commit comments

Comments
 (0)