From 43ebf19dee4bd50a142b91f474188146206bd70f Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Thu, 2 Jan 2025 17:32:32 +0100 Subject: [PATCH] Fix gradient legend width --- R/plot_matrix.R | 18 +- .../tinytest/_tinysnapshot/plot_mtx_count.svg | 526 ++++++++--------- .../_tinysnapshot/plot_mtx_notfixed.svg | 496 ++++++++-------- inst/tinytest/_tinysnapshot/plot_mtx_occ.svg | 20 +- .../tinytest/_tinysnapshot/plot_mtx_prop1.svg | 532 +++++++++--------- .../tinytest/_tinysnapshot/plot_mtx_prop2.svg | 532 +++++++++--------- inst/tinytest/_tinysnapshot/plot_mtx_sim.svg | 14 +- inst/tinytest/_tinysnapshot/plot_spot_occ.svg | 20 +- .../_tinysnapshot/plot_spot_plain.svg | 18 +- .../_tinysnapshot/plot_spot_prop1.svg | 16 +- .../_tinysnapshot/plot_spot_prop2.svg | 14 +- .../tinytest/_tinysnapshot/plot_spot_ring.svg | 18 +- .../_tinysnapshot/plot_spot_sim_plain.svg | 14 +- .../_tinysnapshot/plot_spot_sim_ring.svg | 14 +- 14 files changed, 1128 insertions(+), 1124 deletions(-) diff --git a/R/plot_matrix.R b/R/plot_matrix.R index 14c5c8a..de1e6d2 100644 --- a/R/plot_matrix.R +++ b/R/plot_matrix.R @@ -81,9 +81,12 @@ plot_matrix <- function(object, panel, diag = TRUE, upper = TRUE, lower = TRUE, pin <- graphics::par("pin") plt <- graphics::par("plt") + ## Add horizontal space for the legend (5%) + legend_width <- if (legend) max(1, m / 20) else 0 + if (isTRUE(asp)) asp <- 1 if (!isFALSE(asp) && !is.na(asp)) { - aspect_ratio <- n / (m + legend) + aspect_ratio <- n / (m + legend_width) pin_y <- pin[1] * aspect_ratio * asp if (pin_y < pin[2]) { @@ -99,7 +102,7 @@ plot_matrix <- function(object, panel, diag = TRUE, upper = TRUE, lower = TRUE, } ## Set plotting coordinates - xlim <- c(0, m + legend) + 0.5 + xlim <- c(0, m + legend_width) + 0.5 ylim <- c(0, n) + 0.5 graphics::plot.window(xlim = xlim, ylim = ylim, xaxs = "i", yaxs = "i", asp = asp) @@ -120,19 +123,20 @@ plot_matrix <- function(object, panel, diag = TRUE, upper = TRUE, lower = TRUE, if (legend) { lgd <- attr(data, "legend") legend_gradient(x = m, y = n, labels = lgd$labels, - at = lgd$at, col = lgd$colors) + at = lgd$at, width = legend_width, col = lgd$colors) } } -legend_gradient <- function(x, y, labels, at, col) { +legend_gradient <- function(x, y, labels, at, width, col) { legend_image <- grDevices::as.raster(col) legend_y <- (at - min(at)) * y / diff(range(at)) + 0.5 graphics::rasterImage(legend_image, xleft = x + 1, ybottom = max(legend_y), - xright = x + 1.5, ytop = min(legend_y)) - graphics::segments(x0 = x + 1, y0 = legend_y, x1 = x + 1.5, y1 = legend_y, + xright = x + 1 + width, ytop = min(legend_y)) + graphics::segments(x0 = x + 1, y0 = legend_y, + x1 = x + 1 + width, y1 = legend_y, col = "white") - graphics::polygon(x = c(x, x + 0.5, x + 0.5, x) + 1, + graphics::polygon(x = c(x, x + width, x + width, x) + 1, y = c(0.5, 0.5, max(legend_y), max(legend_y)), col = NA, border = "black") graphics::axis(side = 4, at = legend_y, labels = labels, las = 2) diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_count.svg b/inst/tinytest/_tinysnapshot/plot_mtx_count.svg index d3183e7..7c8737e 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_count.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_count.svg @@ -23,276 +23,276 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -La Paloma +La Paloma El Juyo -Altamira -X1 -X3 -X5 -X7 -X9 -X11 -X13 -X15 -X17 -X19 -X21 -X23 -X25 -X27 -X29 -X31 -X33 -X35 -X37 -X39 -X41 -X43 +Altamira +X1 +X3 +X5 +X7 +X9 +X11 +X13 +X15 +X17 +X19 +X21 +X23 +X25 +X27 +X29 +X31 +X33 +X35 +X37 +X39 +X41 +X43 - - - - - - - + + + + + + + - - - - - -0 -5 -10 -15 + + + + + +0 +5 +10 +15 diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_notfixed.svg b/inst/tinytest/_tinysnapshot/plot_mtx_notfixed.svg index 1cfa968..ef1cce3 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_notfixed.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_notfixed.svg @@ -28,226 +28,226 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + La Paloma @@ -255,36 +255,36 @@ El Juyo Cueto de la Mina Altamira -X1 -X3 -X5 -X7 -X9 -X11 -X13 -X15 -X17 -X19 -X21 -X23 -X25 -X27 -X29 -X31 -X33 -X35 -X37 -X39 -X41 -X43 +X1 +X3 +X5 +X7 +X9 +X11 +X13 +X15 +X17 +X19 +X21 +X23 +X25 +X27 +X29 +X31 +X33 +X35 +X37 +X39 +X41 +X43 - - - - - - + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_occ.svg b/inst/tinytest/_tinysnapshot/plot_mtx_occ.svg index 62bbbcd..9f77c44 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_occ.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_occ.svg @@ -52,16 +52,16 @@ DLH4 - - - - - - - - - - + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_prop1.svg b/inst/tinytest/_tinysnapshot/plot_mtx_prop1.svg index 6356559..a40156c 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_prop1.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_prop1.svg @@ -23,279 +23,279 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -La Paloma +La Paloma El Juyo -Altamira -X1 -X3 -X5 -X7 -X9 -X11 -X13 -X15 -X17 -X19 -X21 -X23 -X25 -X27 -X29 -X31 -X33 -X35 -X37 -X39 -X41 -X43 +Altamira +X1 +X3 +X5 +X7 +X9 +X11 +X13 +X15 +X17 +X19 +X21 +X23 +X25 +X27 +X29 +X31 +X33 +X35 +X37 +X39 +X41 +X43 - - - - - - - - - + + + + + + + + + - - - - - - - - 0% -10% -20% + + + + + + + + 0% +10% +20% diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_prop2.svg b/inst/tinytest/_tinysnapshot/plot_mtx_prop2.svg index 26c0713..786544f 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_prop2.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_prop2.svg @@ -23,279 +23,279 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -La Paloma +La Paloma El Juyo -Altamira -X1 -X3 -X5 -X7 -X9 -X11 -X13 -X15 -X17 -X19 -X21 -X23 -X25 -X27 -X29 -X31 -X33 -X35 -X37 -X39 -X41 -X43 +Altamira +X1 +X3 +X5 +X7 +X9 +X11 +X13 +X15 +X17 +X19 +X21 +X23 +X25 +X27 +X29 +X31 +X33 +X35 +X37 +X39 +X41 +X43 - - - - - - - - - + + + + + + + + + - - - - - - - - 0% - 40% - 80% + + + + + + + + 0% + 40% + 80% diff --git a/inst/tinytest/_tinysnapshot/plot_mtx_sim.svg b/inst/tinytest/_tinysnapshot/plot_mtx_sim.svg index 7c4f33e..650a5dc 100644 --- a/inst/tinytest/_tinysnapshot/plot_mtx_sim.svg +++ b/inst/tinytest/_tinysnapshot/plot_mtx_sim.svg @@ -86,13 +86,13 @@ S170 - - - - - - - + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_occ.svg b/inst/tinytest/_tinysnapshot/plot_spot_occ.svg index 3e4a619..590e471 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_occ.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_occ.svg @@ -60,16 +60,16 @@ DLH4 - - - - - - - - - - + + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_plain.svg b/inst/tinytest/_tinysnapshot/plot_spot_plain.svg index 541cd95..530dc14 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_plain.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_plain.svg @@ -72,15 +72,15 @@ DLH4 - - - - - - - - - + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_prop1.svg b/inst/tinytest/_tinysnapshot/plot_spot_prop1.svg index a786781..1cbd90b 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_prop1.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_prop1.svg @@ -98,14 +98,14 @@ DLH4 - - - - - - - - + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_prop2.svg b/inst/tinytest/_tinysnapshot/plot_spot_prop2.svg index 11de182..8c01f1b 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_prop2.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_prop2.svg @@ -98,13 +98,13 @@ DLH4 - - - - - - - + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_ring.svg b/inst/tinytest/_tinysnapshot/plot_spot_ring.svg index 044df3e..03ef132 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_ring.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_ring.svg @@ -98,15 +98,15 @@ DLH4 - - - - - - - - - + + + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_sim_plain.svg b/inst/tinytest/_tinysnapshot/plot_spot_sim_plain.svg index 9f6002f..e946eea 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_sim_plain.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_sim_plain.svg @@ -86,13 +86,13 @@ S170 - - - - - - - + + + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_spot_sim_ring.svg b/inst/tinytest/_tinysnapshot/plot_spot_sim_ring.svg index 765a5be..ed591c7 100644 --- a/inst/tinytest/_tinysnapshot/plot_spot_sim_ring.svg +++ b/inst/tinytest/_tinysnapshot/plot_spot_sim_ring.svg @@ -122,13 +122,13 @@ S170 - - - - - - - + + + + + + +