Skip to content

Commit

Permalink
No ticks no space (#6071)
Browse files Browse the repository at this point in the history
* no space for blank ticks

* preserve axis text spacing for `theme_minimal()`

* add news bullet
  • Loading branch information
teunbrand authored Dec 2, 2024
1 parent f52de1c commit 3be5d6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},

Expand Down
6 changes: 5 additions & 1 deletion R/theme-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3be5d6c

Please sign in to comment.