From f48e19231c5e0f741276e378b3fb264f3aa73826 Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 20:18:56 +0800 Subject: [PATCH 1/7] Fix theme_blank plot margin --- R/themes.R | 24 ++++++++++++------------ tests/testthat.R | 4 ++++ tests/testthat/test-themes.R | 6 ++++++ 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-themes.R diff --git a/R/themes.R b/R/themes.R index 103897b..06b21e5 100644 --- a/R/themes.R +++ b/R/themes.R @@ -158,10 +158,10 @@ theme_blank <- function( legend.margin = margin(0, 0, 0, 0), legend.key.size = grid::unit(10, "pt"), plot.margin = margin( - lab_size + 2, - lab_size + 2, - lab_size + 2, - lab_size + 2, + lab_size + 8, + lab_size + 8, + lab_size + 8, + lab_size + 8, unit = "points" ) ) @@ -199,10 +199,10 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(0, "npc"), - y = grid::unit(0, "npc"), - vjust = 4 / 3, - hjust = 0, + x = grid::unit(xlen_npc / 2, "npc"), + y = grid::unit(0, "npc") - grid::unit(0.8, "lines"), + vjust = 1, + hjust = 0.5, gp = grid::gpar(fontsize = lab_size) ), grid::linesGrob( @@ -212,10 +212,10 @@ theme_blank <- function( gp = grid::gpar(lwd = 2) ), grid::textGrob( - label = ylab, x = grid::unit(0, "npc"), - y = grid::unit(0, "npc"), - vjust = -2 / 3, - hjust = 0, + label = ylab, x = grid::unit(0, "npc") - grid::unit(0.8, "lines"), + y = grid::unit(ylen_npc / 2, "npc"), + vjust = 0, + hjust = 0.5, rot = 90, gp = grid::gpar(fontsize = lab_size) ) diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..818ccf8 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(thisplot) + +test_check("thisplot") diff --git a/tests/testthat/test-themes.R b/tests/testthat/test-themes.R new file mode 100644 index 0000000..907fcdf --- /dev/null +++ b/tests/testthat/test-themes.R @@ -0,0 +1,6 @@ +test_that("theme_blank leaves room for coordinate annotation", { + theme_layers <- thisplot::theme_blank(add_coord = FALSE, lab_size = 12) + plot_margin <- theme_layers[[1]][[1]]$plot.margin + + expect_equal(as.numeric(plot_margin), rep(20, 4)) +}) From 8071b4f2f0dd27f0a37915b1c9f1c09e0103f1d7 Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:19:48 +0800 Subject: [PATCH 2/7] Adjust theme_blank coordinate label positions for long text --- R/themes.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/themes.R b/R/themes.R index 06b21e5..327617d 100644 --- a/R/themes.R +++ b/R/themes.R @@ -199,10 +199,10 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(xlen_npc / 2, "npc"), - y = grid::unit(0, "npc") - grid::unit(0.8, "lines"), + x = grid::unit(xlen_npc, "npc") + grid::unit(0.5, "lines"), + y = grid::unit(-1.2, "lines"), vjust = 1, - hjust = 0.5, + hjust = 0, gp = grid::gpar(fontsize = lab_size) ), grid::linesGrob( @@ -212,9 +212,10 @@ theme_blank <- function( gp = grid::gpar(lwd = 2) ), grid::textGrob( - label = ylab, x = grid::unit(0, "npc") - grid::unit(0.8, "lines"), - y = grid::unit(ylen_npc / 2, "npc"), - vjust = 0, + label = ylab, + x = grid::unit(-2, "lines"), + y = grid::unit(ylen_npc, "npc") + grid::unit(0.5, "lines"), + vjust = 0.5, hjust = 0.5, rot = 90, gp = grid::gpar(fontsize = lab_size) From d29a6cf7e4b2434da239a76ac1decd1efc79b7cf Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:26:15 +0800 Subject: [PATCH 3/7] Fine tune theme_blank coordinate label offsets for balanced spacing --- R/themes.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/themes.R b/R/themes.R index 327617d..24cc174 100644 --- a/R/themes.R +++ b/R/themes.R @@ -199,8 +199,8 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(xlen_npc, "npc") + grid::unit(0.5, "lines"), - y = grid::unit(-1.2, "lines"), + x = grid::unit(xlen_npc, "npc") + grid::unit(0.15, "lines"), + y = grid::unit(-0.95, "lines"), vjust = 1, hjust = 0, gp = grid::gpar(fontsize = lab_size) @@ -213,8 +213,8 @@ theme_blank <- function( ), grid::textGrob( label = ylab, - x = grid::unit(-2, "lines"), - y = grid::unit(ylen_npc, "npc") + grid::unit(0.5, "lines"), + x = grid::unit(-1.0, "lines"), + y = grid::unit(ylen_npc, "npc") + grid::unit(0.15, "lines"), vjust = 0.5, hjust = 0.5, rot = 90, From adeec64a006416afd011235c193881ca6072991d Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:30:23 +0800 Subject: [PATCH 4/7] Nudge theme_blank x-axis label downward to avoid x-label overlap --- R/themes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/themes.R b/R/themes.R index 24cc174..bc7189b 100644 --- a/R/themes.R +++ b/R/themes.R @@ -200,8 +200,8 @@ theme_blank <- function( grid::textGrob( label = xlab, x = grid::unit(xlen_npc, "npc") + grid::unit(0.15, "lines"), - y = grid::unit(-0.95, "lines"), - vjust = 1, + y = grid::unit(-1.05, "lines"), + vjust = 0, hjust = 0, gp = grid::gpar(fontsize = lab_size) ), From e1c44d07f199b52e800046e3119c0ea88b6f6c7c Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:32:37 +0800 Subject: [PATCH 5/7] Further tune x-axis label offset in theme_blank --- R/themes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/themes.R b/R/themes.R index bc7189b..4869489 100644 --- a/R/themes.R +++ b/R/themes.R @@ -199,8 +199,8 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(xlen_npc, "npc") + grid::unit(0.15, "lines"), - y = grid::unit(-1.05, "lines"), + x = grid::unit(xlen_npc, "npc") + grid::unit(0.35, "lines"), + y = grid::unit(-1.2, "lines"), vjust = 0, hjust = 0, gp = grid::gpar(fontsize = lab_size) From 34c1b0b49ab1d749bbd3f809dcaed57cab8a4b43 Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:34:08 +0800 Subject: [PATCH 6/7] Pull x-axis coordinate label slightly further from axis line --- R/themes.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/themes.R b/R/themes.R index 4869489..f5e43b5 100644 --- a/R/themes.R +++ b/R/themes.R @@ -200,7 +200,7 @@ theme_blank <- function( grid::textGrob( label = xlab, x = grid::unit(xlen_npc, "npc") + grid::unit(0.35, "lines"), - y = grid::unit(-1.2, "lines"), + y = grid::unit(-1.35, "lines"), vjust = 0, hjust = 0, gp = grid::gpar(fontsize = lab_size) From 6f75085dcfdf1dfcb8c7b3dd477a5a48831ece62 Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Mon, 8 Jun 2026 21:39:29 +0800 Subject: [PATCH 7/7] Match theme_blank axis label offsets to upstream original layout --- R/themes.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/themes.R b/R/themes.R index f5e43b5..8d8b321 100644 --- a/R/themes.R +++ b/R/themes.R @@ -199,9 +199,9 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(xlen_npc, "npc") + grid::unit(0.35, "lines"), - y = grid::unit(-1.35, "lines"), - vjust = 0, + x = grid::unit(0, "npc"), + y = grid::unit(0, "npc"), + vjust = 4 / 3, hjust = 0, gp = grid::gpar(fontsize = lab_size) ), @@ -213,10 +213,10 @@ theme_blank <- function( ), grid::textGrob( label = ylab, - x = grid::unit(-1.0, "lines"), - y = grid::unit(ylen_npc, "npc") + grid::unit(0.15, "lines"), - vjust = 0.5, - hjust = 0.5, + x = grid::unit(0, "npc"), + y = grid::unit(0, "npc"), + vjust = -2 / 3, + hjust = 0, rot = 90, gp = grid::gpar(fontsize = lab_size) )