Skip to content

Commit d0adb16

Browse files
committed
vizualization adjustments
1 parent 93b7862 commit d0adb16

4 files changed

Lines changed: 11 additions & 21 deletions

File tree

R/enrichItPlot.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ enrichItPlot <- function(res,
6868
if (plot.type == "bar") {
6969
p <- ggplot2::ggplot(res,
7070
ggplot2::aes(x = .data[[x.measure]], y = .data$Term)) +
71-
ggplot2::geom_col(fill = .colorizer(palette, n = 1), ...) +
72-
ggplot2::facet_wrap(~ Database, scales = "free_y") +
71+
ggplot2::geom_col(fill = .colorizer(palette, n = 1)) +
7372
ggplot2::labs(x = x.measure, y = NULL) +
7473
ggplot2::theme_classic()
7574

@@ -80,19 +79,14 @@ enrichItPlot <- function(res,
8079
hjust = 0, size = 3)
8180
}
8281
p <- p + ggplot2::coord_cartesian(clip = "off")
83-
return(patchwork::wrap_plots(p))
84-
8582
## Dot Plot
8683
} else if (plot.type == "dot") {
87-
if (!requireNamespace("patchwork", quietly = TRUE))
88-
stop("Install 'patchwork' for facetted output.")
8984

9085
p <- ggplot2::ggplot(res,
9186
ggplot2::aes(x = .data$geneRatio, y = .data$Term,
9287
color = .data[[color.measure]],
9388
size = .data$size*.data$geneRatio)) +
9489
ggplot2::geom_point(...) +
95-
ggplot2::facet_wrap(~ Database, scales = "free_y") +
9690
ggplot2::scale_size_continuous(name = "Core Count") +
9791
ggplot2::labs(x = "geneRatio", y = NULL,
9892
color = color.measure) +
@@ -101,8 +95,6 @@ enrichItPlot <- function(res,
10195

10296
if (!is.null(palette))
10397
p <- p + ggplot2::scale_color_gradientn(colors = .colorizer(palette, 11))
104-
return(patchwork::wrap_plots(p))
105-
10698
# Network Plot
10799
} else {
108100
if (!requireNamespace("ggraph", quietly = TRUE))
@@ -126,7 +118,7 @@ enrichItPlot <- function(res,
126118
igraph::V(g)$type <- ifelse(igraph::V(g)$name %in% res$pathway, "pathway", "gene")
127119
igraph::V(g)$size <- ifelse(igraph::V(g)$type == "pathway", 8, 3)
128120

129-
ggraph::ggraph(g, layout = "fr") +
121+
p <- ggraph::ggraph(g, layout = "fr") +
130122
ggraph::geom_edge_link(aes(alpha = after_stat(index)), show.legend = FALSE) +
131123
ggraph::geom_node_point(aes(size = .data$size,
132124
color = .data$type)) +
@@ -135,5 +127,8 @@ enrichItPlot <- function(res,
135127
vjust = 1.5, check_overlap = TRUE) +
136128
ggplot2::scale_color_manual(values = .colorizer(palette, n = 2)) +
137129
ggplot2::theme_void()
130+
131+
138132
}
133+
return(p)
139134
}

R/pcaEnrichment.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ pcaEnrichment <- function(input.data,
140140
ggplot2::geom_segment(data = loadings,
141141
ggplot2::aes(x = 0, y = 0, xend = xend, yend = yend),
142142
arrow = ggplot2::arrow(length = grid::unit(0.25, "cm"))) +
143-
ggplot2::geom_text(data = loadings,
143+
ggplot2::geom_label(data = loadings,
144144
ggplot2::aes(x = xend, y = yend, label = names),
145-
size = 2, vjust = 1.1)
145+
size = 2)
146146
}
147147

148148
g

R/ridgeEnrichment.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ ridgeEnrichment <- function(input.data,
123123
xlab(paste0(gene.set.use, "\nEnrichment Score")) +
124124
ggplot2::theme_classic(base_size = 11)
125125

126-
p <- .colorby(df, p, color.by, palette, type = "fill")
126+
p <- .colorby(df, p, color.by, palette, type = "fill") +
127+
guides(fill = "none")
127128

128129
## facetting ------------------------------------------------------------
129130
if (!is.null(facet.by))

tests/testthat/test-enrichItPlot.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# test script for enrichItPlot.R - testcases are NOT comprehensive!
22

33
skip_if_not_installed("fgsea")
4-
skip_if_not_installed("patchwork")
54

65
# helper data: run a very small fgsea ----------------------------------------
76
set.seed(42)
@@ -31,20 +30,15 @@ res$Database <- ifelse(grepl("^DB1_", res$pathway), "DB1", "DB2")
3130
test_that("bar plot returns a patchwork object with ggplot inside", {
3231
plt <- enrichItPlot(res, plot.type = "bar", top = 3)
3332

34-
expect_s3_class(plt, "patchwork")
35-
expect_true(inherits(plt[[1]], "ggplot"))
33+
expect_true(inherits(plt, "ggplot"))
3634
})
3735

3836
# ---------------------------------------------------------------------------
3937
# 2. DOT plot ---------------------------------------------------------------
4038
test_that("dot plot returns a patchwork object and respects top argument", {
4139
plt <- enrichItPlot(res, plot.type = "dot", top = 1)
4240

43-
expect_s3_class(plt, "patchwork")
44-
# only one term per database should survive top = 1
45-
build <- ggplot2::ggplot_build(plt[[1]])
46-
n_terms <- length(unique(build$data[[1]]$y))
47-
expect_lte(n_terms, 2) # 2 databases ⇒ ≤2 rows in panel 1
41+
expect_true(inherits(plt, "ggplot"))
4842
})
4943

5044
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)