Sitelet https://github.com/tidyverse/ggplot2/pull/6771
Skip to content

Add theme(axis.ontop) - #6771

Merged
teunbrand merged 7 commits into
tidyverse:mainfrom
teunbrand:axis_ontop
Oct 2, 2026
Merged

teunbrand merged 7 commits into
tidyverse:mainfrom
teunbrand:axis_ontop

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This PR aims to fix #6456.

It adds a new theme option that controls whether axes get displayed on top or below the panels.
The mechanism is changing the z value in the gtable.
By default, they are displayed on top of panels.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

p <- ggplot() +
  annotate(
    "rect", xmin = 0, xmax = 1, ymin = 0, ymax = 1,
    colour = "dodgerblue", linewidth = 10, fill = NA
  ) +
  coord_cartesian(
    expand = FALSE,
    clip = "off"
  ) +
  theme(
    axis.line = element_line("tomato", linewidth = 1)
  )

p

Here they are displayed beneath panels.

p + theme(axis.ontop = FALSE)

@teunbrand
teunbrand requested a review from thomasp85 September 24, 2026 09:59

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand
teunbrand merged commit d87cb44 into tidyverse:main Oct 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Could the theme support axis lines and ticks being _not_ on top of geoms?

2 participants