Skip to content

negative axis.ticks.length forces strip.placement to be inside #5251

Closed

Description

@modmost

When trying to force the axis ticks to be inside the figure (using negative axis.ticks.length) from all sides (using dup.axis), the ticks appear on the outside of the strip text. Previous versions used to plot the ticks correctly inside the plot

Here is an example of this

library(ggplot2)

ggplot(mpg, aes(displ, cty)) + 
  geom_point() + 
  facet_grid(drv~cyl) +  
  scale_y_continuous(sec.axis = dup_axis()) + 
  scale_x_continuous(sec.axis = dup_axis()) +
  theme(strip.placement = "outside",
        axis.text.x.bottom = element_text(margin = margin(5,0,0,0)),
        axis.text.y.left = element_text(margin = margin(0,4,0,0)),
        axis.text.x.top = element_blank(), axis.title.x.top = element_blank(),
        axis.text.y.right = element_blank(), axis.title.y.right = element_blank(),
        axis.ticks.length = unit(-3, "point")) 

Running this code on ggplot2 v3.4.1 produces this image
image
Note that the ticks are outside the strip text

While running the code on older versions (e.g. v3.3.1) produces the ticks in the right place. see image below

image

Session info for the top image

> sessioninfo::session_info()
─ Session info ──────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_Canada.utf8
 ctype    English_Canada.utf8
 tz       America/Denver
 date     2023-03-27
 rstudio  2022.12.0+353 Elsbeth Geranium (desktop)
 pandoc   NA

─ Packages ──────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cli           3.6.1   2023-03-23 [1] CRAN (R 4.2.3)
 colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.2.2)
 dplyr         1.1.1   2023-03-22 [1] CRAN (R 4.2.3)
 fansi         1.0.4   2023-01-22 [1] CRAN (R 4.2.2)
 farver        2.1.1   2022-07-06 [1] CRAN (R 4.2.1)
 generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.1)
 ggplot2     * 3.4.1   2023-02-10 [1] CRAN (R 4.2.3)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.1)
 gtable        0.3.3   2023-03-21 [1] CRAN (R 4.2.3)
 labeling      0.4.2   2020-10-20 [1] CRAN (R 4.2.0)
 lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.1)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.1)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.1)
 pillar        1.9.0   2023-03-22 [1] CRAN (R 4.2.3)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.1)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.1)
 rlang         1.1.0   2023-03-14 [1] CRAN (R 4.2.3)
 rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.1)
 scales        1.2.1   2022-08-20 [1] CRAN (R 4.2.1)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.1)
 tibble        3.2.1   2023-03-20 [1] CRAN (R 4.2.3)
 tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.1)
 utf8          1.2.3   2023-01-31 [1] CRAN (R 4.2.2)
 vctrs         0.6.1   2023-03-22 [1] CRAN (R 4.2.3)
 withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.1)

 [1] C:/Users/mod_m/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.2/library

─────────────────────────────────────────────────────────────────────────────────

Activity

  1. changed the title [-]negative axis.ticks.length forces strip.placement to be inside[/-] [+]negative `axis.ticks.length` forces `strip.placement` to be inside[/+] on Mar 27, 2023
  2. added
    bug
    on Mar 27, 2023
  3. teunbrand commented on Mar 27, 2023

    @teunbrand
    Collaborator

    Thanks for the report! I can confirm this bug.

  4. teunbrand commented on Apr 3, 2023

    @teunbrand
    Collaborator

    Here is a more minimal reprex:

    library(ggplot2)
    
    ggplot(mpg, aes(displ, hwy)) +
      facet_grid("foo" ~ drv, switch = "both") +
      theme(
        strip.placement = "outside",
        axis.ticks.length = unit(-3, "pt"),
        axis.text = element_blank()
      )

    Created on 2023-04-03 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfacets 💎guides 📏

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions