Skip to content
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

Automatically remove the tick length when tick is blank #6069

Open
Yunuuuu opened this issue Sep 1, 2024 · 2 comments · May be fixed by #6071
Open

Automatically remove the tick length when tick is blank #6069

Yunuuuu opened this issue Sep 1, 2024 · 2 comments · May be fixed by #6071
Labels
visual change 👩‍🎨 Rendering change that will affect look of output

Comments

@Yunuuuu
Copy link

Yunuuuu commented Sep 1, 2024

In situations when we want to remove margins, we must set both ticks and ticks length to remove the width/heigth of axis in the underlying gtable. As user would expect the empty size when they remove the axis using element_blank().

Issue in stackoverflow: https://stackoverflow.com/questions/40407498/how-to-remove-margins-in-ggplot2-chart

Please note the 10th height which is the height of the axis grob.

library(ggplot2)
p1 <- ggplot(mtcars) +
  geom_point(aes(mpg, disp)) +
  theme(
    axis.title.x = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank(),
    plot.margin = margin()
  )
ggplotGrob(p1)$heights
#>  [1] 0points                                                                 
#>  [2] 0points                                                                 
#>  [3] 0cm                                                                     
#>  [4] 0cm                                                                     
#>  [5] 0cm                                                                     
#>  [6] 0points                                                                 
#>  [7] 0cm                                                                     
#>  [8] 0cm                                                                     
#>  [9] 1null                                                                   
#> [10] sum(0.0966514459665145cm, max(0points, -0.0966514459665145cm), 0cm, 0cm)
#> [11] 0cm                                                                     
#> [12] 0points                                                                 
#> [13] 0cm                                                                     
#> [14] 0cm                                                                     
#> [15] 0points                                                                 
#> [16] 0points
ggplotGrob(p1 +
  theme(axis.ticks.length = unit(0, "mm")))$heights
#>  [1] 0points                               0points                              
#>  [3] 0cm                                   0cm                                  
#>  [5] 0cm                                   0points                              
#>  [7] 0cm                                   0cm                                  
#>  [9] 1null                                 sum(0cm, max(0points, 0cm), 0cm, 0cm)
#> [11] 0cm                                   0points                              
#> [13] 0cm                                   0cm                                  
#> [15] 0points                               0points

Created on 2024-09-01 with reprex v2.1.0

@teunbrand
Copy link
Collaborator

I've raised a similar issue before in #4722, but now that more people would want this, I think we should only reserve space for the elements that are drawn even more.

@teunbrand teunbrand linked a pull request Sep 3, 2024 that will close this issue
@teunbrand teunbrand added the visual change 👩‍🎨 Rendering change that will affect look of output label Sep 3, 2024
@Yunuuuu
Copy link
Author

Yunuuuu commented Sep 4, 2024

Thank you for pointing that out. I see the relevance of the previous issue. However, the current implementation of axis.ticks.length might cause confusion for users, even if it aligns with the design principles of ggplot2. It may be worth considering a revision to improve clarity and user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visual change 👩‍🎨 Rendering change that will affect look of output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants