From b6e736c6f639d23ec230db4d7aa2612f706a6470 Mon Sep 17 00:00:00 2001 From: Ivo Kwee Date: Fri, 16 Jan 2026 11:52:50 +0100 Subject: [PATCH] feat: enhance volcano plot and multipartite graph plotting functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ggVolcano improvements: - Add xlim parameter for manual x-axis limit control - Add ggrepel.padding parameter (default: 0.1) for label spacing control - Change max.overlaps from 20 to Inf to show all labels without limit - Improve axis scaling for better plot aesthetics: - Y-axis: add 5% top padding (0.05 expansion) - X-axis: symmetric 7% padding on both sides (0.07, 0.07) - Auto-calculate xlim from data range if not specified plotMultiPartiteGraph2 improvements: - Make edge.sign parameter options explicit: "both", "pos", "neg", "consensus" - Make edge.type parameter options explicit: "both", "inter", "intra", "both2" - Improved self-documenting code showing all available options These changes improve: - Label visibility and customization in volcano plots - Plot margin handling and aesthetics - Code documentation and usability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- R/pgx-plotting.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/pgx-plotting.R b/R/pgx-plotting.R index 76cf0456..50152381 100644 --- a/R/pgx-plotting.R +++ b/R/pgx-plotting.R @@ -1305,7 +1305,8 @@ ggVolcano <- function(x, ylab = "significance (-log10q)", lfc = 1, psig = 0.05, - ylim = NULL, + xlim = NULL, + ylim = NULL, showlegend = TRUE, marker.size = 2.5, marker.alpha = 0.7, @@ -1319,6 +1320,7 @@ ggVolcano <- function(x, notsel = "#cccccc88", down = "#3181de" ), + ggrepel.padding = 0.1, girafe = FALSE) { if (is.null(highlight)) highlight <- names if (showlegend) { @@ -1346,6 +1348,7 @@ ggVolcano <- function(x, df$name <- gsub("[\\'\\`-]", "", df$name) if (is.null(ylim)) ylim <- max(y, na.rm = TRUE) * 1.1 + if (is.null(xlim)) xlim <- range(x, na.rm = TRUE) plt <- ggplot2::ggplot(df, ggplot2::aes(x = fc, y = y)) + ggplot2::geom_point( @@ -1425,7 +1428,8 @@ ggVolcano <- function(x, plt <- plt + ggrepel::geom_label_repel( ggplot2::aes(label = label, color = category), - size = label.cex, family = "lato", box.padding = 0.1, max.overlaps = 20, show.legend = FALSE + size = label.cex, family = "lato", box.padding = ggrepel.padding, + max.overlaps = Inf, show.legend = FALSE ) plt <- plt + @@ -1434,9 +1438,12 @@ ggVolcano <- function(x, ggplot2::geom_vline(xintercept = 0, linetype = "solid", color = "darkgrey") + ggplot2::scale_y_continuous( limits = c(0, ylim), - expand = ggplot2::expansion(mult = c(0, 0)) + expand = ggplot2::expansion(mult = c(0, 0.05)) + ) + + ggplot2::scale_x_continuous( + limits = xlim, + expand = ggplot2::expansion(mult = c(0.07, 0.07)) ) + - ggplot2::scale_x_continuous(expand = ggplot2::expansion(mult = c(0.1, 0))) + ggplot2::labs(x = xlab, y = ylab) + guides(colour = guide_legend(reverse = T)) + ggplot2::theme_minimal(base_size = 15) + @@ -7120,7 +7127,8 @@ plotMultiPartiteGraph2 <- function(graph, layers = NULL, xpos = NULL, xlim = NULL, justgraph = FALSE, edge.cex = 1, edge.alpha = 0.33, xdist = 1, normalize.edges = FALSE, yheight = 2, - edge.sign = "both", edge.type = "both", + edge.sign = c("both","pos","neg","consensus")[1], + edge.type = c("both","inter","intra","both2")[1], labpos = NULL, value.name = NULL, strip.prefix = FALSE, strip.prefix2 = FALSE, prune = FALSE, @@ -7511,3 +7519,4 @@ plotAdjacencyMatrixFromGraph <- function(graph, nmax = 40, binary = FALSE, sym = TRUE, ... ) } +