diff --git a/NEWS.md b/NEWS.md index 6e3896e061..c0097b2de4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -219,6 +219,8 @@ * New theme elements `palette.{aes}.discrete` and `palette.{aes}.continuous`. Theme palettes replace palettes in scales where `palette = NULL`, which is the new default in many scales (@teunbrand, #4696). +* `guide_axis()` no longer reserves space for blank ticks + (@teunbrand, #4722, #6069). # ggplot2 3.5.1 diff --git a/R/guide-axis.R b/R/guide-axis.R index bc2a2e1596..70ac3da43f 100644 --- a/R/guide-axis.R +++ b/R/guide-axis.R @@ -256,6 +256,12 @@ GuideAxis <- ggproto( override_elements = function(params, elements, theme) { elements$text <- label_angle_heuristic(elements$text, params$position, params$angle) + if (inherits(elements$ticks, "element_blank")) { + elements$major_length <- unit(0, "cm") + } + if (inherits(elements$minor, "element_blank") || isFALSE(params$minor.ticks)) { + elements$minor_length <- unit(0, "cm") + } return(elements) }, diff --git a/R/theme-defaults.R b/R/theme-defaults.R index 88aa05146b..ac8c5ecb51 100644 --- a/R/theme-defaults.R +++ b/R/theme-defaults.R @@ -451,7 +451,11 @@ theme_minimal <- function(base_size = 11, base_family = "", ink = ink, paper = paper ) %+replace% theme( - axis.ticks = element_blank(), + axis.ticks = element_blank(), # Extra margins due to absence ticks + axis.text.x.bottom = element_text(margin = margin(t = 0.45 * base_size)), + axis.text.x.top = element_text(margin = margin(b = 0.45 * base_size)), + axis.text.y.left = element_text(margin = margin(r = 0.45 * base_size)), + axis.text.y.right = element_text(margin = margin(l = 0.45 * base_size)), legend.background = element_blank(), legend.key = element_blank(), panel.background = element_blank(),