From 6317e85323878ff3984e526f9f16638db4daa7fe Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Tue, 9 Jun 2026 00:42:49 +0800 Subject: [PATCH 1/2] Refine theme_blank coordinate annotation layout --- R/themes.R | 22 +++++++++++----------- tests/testthat/test-themes.R | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/themes.R b/R/themes.R index 8d8b321..1df7ac3 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 + 8, - lab_size + 8, - lab_size + 8, - lab_size + 8, + lab_size + 10, + lab_size + 10, + lab_size + 10, + lab_size + 10, unit = "points" ) ) @@ -199,9 +199,9 @@ theme_blank <- function( ), grid::textGrob( label = xlab, - x = grid::unit(0, "npc"), - y = grid::unit(0, "npc"), - vjust = 4 / 3, + x = grid::unit(xlen_npc, "npc") + grid::unit(0.25, "lines"), + y = grid::unit(-0.75, "lines"), + vjust = 1, hjust = 0, gp = grid::gpar(fontsize = lab_size) ), @@ -213,10 +213,10 @@ theme_blank <- function( ), grid::textGrob( label = ylab, - x = grid::unit(0, "npc"), - y = grid::unit(0, "npc"), - vjust = -2 / 3, - hjust = 0, + x = grid::unit(-0.85, "lines"), + y = grid::unit(ylen_npc, "npc") + grid::unit(0.25, "lines"), + vjust = 0.5, + hjust = 0.5, rot = 90, gp = grid::gpar(fontsize = lab_size) ) diff --git a/tests/testthat/test-themes.R b/tests/testthat/test-themes.R index 907fcdf..4f1d47c 100644 --- a/tests/testthat/test-themes.R +++ b/tests/testthat/test-themes.R @@ -2,5 +2,5 @@ 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)) + expect_equal(as.numeric(plot_margin), rep(22, 4)) }) From 63f242b4c065881b0b4b72bc99b656846efddb41 Mon Sep 17 00:00:00 2001 From: hurry060215-tech Date: Tue, 9 Jun 2026 01:01:38 +0800 Subject: [PATCH 2/2] Align theme_blank x-axis label with coordinate origin --- R/themes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/themes.R b/R/themes.R index 1df7ac3..909adcd 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.25, "lines"), - y = grid::unit(-0.75, "lines"), + x = grid::unit(0, "npc"), + y = grid::unit(-0.55, "lines"), vjust = 1, hjust = 0, gp = grid::gpar(fontsize = lab_size)