Skip to content

Axis ticks reserve space, even when absent #4722

@teunbrand

Description

@teunbrand

Hi there,

I've come across a few cases on SO where some confusion was created by axis ticks creating whitespace around the plot, even when axis.ticks = element_blank() (example 1, example 2). I'm not sure whether this is intentional or not, but I found it to be a bit counterintuitive. To illustrate:

library(ggplot2)

p <- ggplot(mpg, aes(displ, cty)) +
  geom_point()

p +
  theme(
    axis.ticks = element_blank(),
    axis.ticks.length = unit(2, "cm") # exaggerated for clarity
  )

There are other ways to arrive at the same plot without the involvement of axis tick length, so it doesn't seem like the axis tick lengths are a necessary part for this purpose.

p +
  theme(
    axis.ticks = element_blank(),
    axis.text.x.bottom = element_text(margin = margin(t = 2, unit = "cm")),
    axis.text.y.left   = element_text(margin = margin(r = 2, unit = "cm"))
  )

Created on 2022-02-01 by the reprex package (v2.0.1)

If the ggplot2 maintainers agree with me, I could draft a PR to remove the empty space when the axis ticks are blank.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions