Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
davidhodge931 opened this issue May 13, 2025 · 0 comments
Labels
feature a feature request or enhancement themes 💃

Comments

@davidhodge931
Copy link

davidhodge931 commented May 13, 2025

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

@davidhodge931 davidhodge931 changed the title Feature request: Could the theme support axis lines and ticks being _not_ on top of geoms? Could the theme support axis lines and ticks being _not_ on top of geoms? May 21, 2025
@teunbrand teunbrand added themes 💃 feature a feature request or enhancement labels May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement themes 💃
Projects
None yet
Development

No branches or pull requests

2 participants