From 386e39f5f2725c80e872eee83d0affcd6deda98c Mon Sep 17 00:00:00 2001 From: schochastics Date: Fri, 27 Jun 2025 12:57:50 +0200 Subject: [PATCH 1/3] added mark lwd --- R/plot.R | 21 ++++++++++++++++++--- man/plot.igraph.Rd | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/R/plot.R b/R/plot.R index 667fb62daeb..07627ee62aa 100644 --- a/R/plot.R +++ b/R/plot.R @@ -57,6 +57,10 @@ #' the marked vertex groups. It is in the same units as the vertex sizes. If a #' vector is given, then different values are used for the different vertex #' groups. +#' @param mark.lwd A numeric scalar or vector, the linewidth of the border around +#' the marked vertex groups. If a +#' vector is given, then different values are used for the different vertex +#' groups. #' @param loop.size A numeric scalar that allows the user to scale the loop edges #' of the network. The default loop size is 1. Larger values will produce larger #' loops. @@ -92,6 +96,7 @@ plot.igraph <- function( mark.col = rainbow(length(mark.groups), alpha = 0.3), mark.border = rainbow(length(mark.groups), alpha = 1), mark.expand = 15, + mark.lwd = 1, loop.size = 1, ... ) { @@ -252,6 +257,7 @@ plot.igraph <- function( mark.border <- rep(mark.border, length.out = length(mark.groups)) mark.col <- rep(mark.col, length.out = length(mark.groups)) mark.expand <- rep(mark.expand, length.out = length(mark.groups)) + mark.lwd <- rep(mark.lwd, length.out = length(mark.lwd)) for (g in seq_along(mark.groups)) { .members <- mark.groups[[g]] @@ -267,7 +273,8 @@ plot.igraph <- function( expand.by = mark.expand[g] / 200, shape = mark.shape[g], col = mark.col[g], - border = mark.border[g] + border = mark.border[g], + border.lwd = mark.lwd[g] ) } @@ -1800,7 +1807,8 @@ igraph.polygon <- function( expand.by = 15 / 200, shape = 1 / 2, col = "#ff000033", - border = NA + border = NA, + border.lwd = 1 ) { by <- expand.by pp <- rbind( @@ -1812,5 +1820,12 @@ igraph.polygon <- function( ) cl <- convex_hull(pp) - xspline(cl$rescoords, shape = shape, open = FALSE, col = col, border = border) + xspline( + cl$rescoords, + shape = shape, + open = FALSE, + col = col, + border = border, + lwd = border.lwd + ) } diff --git a/man/plot.igraph.Rd b/man/plot.igraph.Rd index 36451e890b8..c1ee1232a98 100644 --- a/man/plot.igraph.Rd +++ b/man/plot.igraph.Rd @@ -16,6 +16,7 @@ mark.col = rainbow(length(mark.groups), alpha = 0.3), mark.border = rainbow(length(mark.groups), alpha = 1), mark.expand = 15, + mark.lwd = 1, loop.size = 1, ... ) @@ -58,6 +59,11 @@ the marked vertex groups. It is in the same units as the vertex sizes. If a vector is given, then different values are used for the different vertex groups.} +\item{mark.lwd}{A numeric scalar or vector, the linewidth of the border around +the marked vertex groups. If a +vector is given, then different values are used for the different vertex +groups.} + \item{loop.size}{A numeric scalar that allows the user to scale the loop edges of the network. The default loop size is 1. Larger values will produce larger loops.} From b5524fbd14356c1680c31e188e565013f2447a4c Mon Sep 17 00:00:00 2001 From: schochastics Date: Fri, 27 Jun 2025 12:59:54 +0200 Subject: [PATCH 2/3] fixed wrong expansion --- R/plot.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/plot.R b/R/plot.R index 07627ee62aa..f5caa12485f 100644 --- a/R/plot.R +++ b/R/plot.R @@ -257,7 +257,7 @@ plot.igraph <- function( mark.border <- rep(mark.border, length.out = length(mark.groups)) mark.col <- rep(mark.col, length.out = length(mark.groups)) mark.expand <- rep(mark.expand, length.out = length(mark.groups)) - mark.lwd <- rep(mark.lwd, length.out = length(mark.lwd)) + mark.lwd <- rep(mark.lwd, length.out = length(mark.groups)) for (g in seq_along(mark.groups)) { .members <- mark.groups[[g]] @@ -1820,6 +1820,7 @@ igraph.polygon <- function( ) cl <- convex_hull(pp) + xspline( cl$rescoords, shape = shape, From c00c3f4647c0f612602022b25ea4343b04baf1d0 Mon Sep 17 00:00:00 2001 From: schochastics Date: Thu, 3 Jul 2025 11:25:34 +0200 Subject: [PATCH 3/3] added test --- .../testthat/_snaps/plot/mark-border-lwd.svg | 40 +++++++++++++++++++ tests/testthat/test-plot.R | 23 +++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/testthat/_snaps/plot/mark-border-lwd.svg diff --git a/tests/testthat/_snaps/plot/mark-border-lwd.svg b/tests/testthat/_snaps/plot/mark-border-lwd.svg new file mode 100644 index 00000000000..2bf2b3a917d --- /dev/null +++ b/tests/testthat/_snaps/plot/mark-border-lwd.svg @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index 171f6bb7568..106bdeb0546 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -154,3 +154,26 @@ test_that("Arrow drawing works correctly", { } vdiffr::expect_doppelganger("standard-arrow-sizes", standard_arrow_sizes) }) + +test_that("mark border linewidth", { + skip_if_not_installed("vdiffr") + mark_border_lwd <- function() { + g <- make_full_graph(4, directed = FALSE) + V(g)$x <- c(1, 2, 2, 1) + V(g)$y <- c(1, 1, 2, 2) + wc <- cluster_walktrap(g) + plot( + wc, + g, + vertex.label = NA, + vertex.size = 20, + mark.shape = 0, + edge.width = 0.1, + mark.expand = 40, + mark.lwd = 5, + margin = 1 + ) + } + + vdiffr::expect_doppelganger("mark-border-lwd", mark_border_lwd) +})