tidyverse / tidyverse/ggplot2

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

Open
#6,456 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature themes :dancer:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

There are situations where it would nice to be able to easily make the the axis line/ticks not be on top of geoms.

I noticed the theme argument has a panel.ontop argument. So I wondered if you guys would consider adding equivalent theme arguments for the axis.

Something like theme(axis.ontop = TRUE, axis.ontop.x = TRUE, axis.ontop.y = TRUE).

I suppose for consistency with the existing theme grammar, these axis arguments should apply to the axis text too.

Thanks for your consideration, and the great ggplot2 dev work!

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(palmerpenguins)
#> 
#> Attaching package: 'palmerpenguins'
#> The following objects are masked from 'package:datasets':
#> 
#>     penguins, penguins_raw

d <- penguins |>
  add_row(
    flipper_length_mm = 190,
    body_mass_g = 2500,
    species = "Adelie",
  ) |> 
  add_row(
    flipper_length_mm = 165,
    body_mass_g = 3000,
    species = "Adelie",
  )

p <- d |>
  ggplot() +
  geom_point(aes(x = flipper_length_mm, y = body_mass_g),
             colour = "steelblue", size = 3) +
  theme_classic() +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  coord_cartesian(clip = "off")

p
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_point()`).


#so something like this to make the axis line/ticks not ontop
# p +
#   theme(axis.ontop = FALSE) 
# 
# p +
#   theme(axis.ontop.x = FALSE) +
#   theme(axis.ontop.y = FALSE) 

Created on 2025-05-14 with reprex v2.1.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing theme panel.ontop behavior and how axis lines, ticks, and text are rendered in ggplot2. Determine whether the proposed axis.ontop, axis.ontop.x, and axis.ontop.y settings can fit the theme grammar, then verify that the chosen behavior applies consistently to the relevant axis components.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.