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

easy_rotate_*_labels: consider updating the hjust and vjust be updated? #79

Open
davidhodge931 opened this issue Oct 30, 2024 · 5 comments

Comments

@davidhodge931
Copy link

Demo as how your functions rotate the text, compared to an alternative suggestion.

Would require breaking code to change, so not sure if you're up for that or not

library(tidyverse)
library(palmerpenguins)

penguins |> 
  ggplot() +
  geom_bar(aes(x = species, fill = island)) +
  ggeasy::easy_rotate_x_labels(teach = TRUE) 

penguins |> 
  ggplot() +
  geom_bar(aes(x = species, fill = island)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))  

penguins |> 
  mutate(species = ifelse(species == "Adelie", paste0(species, "\nspecies"), as.character(species))) |>
  ggplot() +
  geom_bar(aes(y = species, fill = island)) +
  ggeasy::easy_rotate_y_labels(teach = TRUE) 

penguins |> 
  mutate(species = ifelse(species == "Adelie", paste0(species, "\nspecies"), as.character(species))) |>
  ggplot() +
  geom_bar(aes(y = species, fill = island)) +
  theme(axis.text.y = element_text(angle = 90, hjust = 0.5, vjust = 0))  
@jonocarroll
Copy link
Owner

The side argument in ggeasy::easy_rotate_x_labels(side = "right") already sets the hjust according to

left = 0
middle = 0.5
right = 1

and maybe that's not the best name for it, but there's no argument for the vjust in {ggeasy}.

I could add an additional vertical argument that adjusts vjust. Other suggestions?

@davidhodge931
Copy link
Author

Ah, I don't think my way is as flexible as yours.. it works for rotating 90, but not for other angles

@davidhodge931
Copy link
Author

I think it's best to have minimal new concepts for people to learn

An idea is to have a couple of optimised shortcut 90 degree functions..

easy_rotate_x_labels_90 <- function() {
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))  
} 

easy_rotate_y_labels_90 <- function() {
  theme(axis.text.y = element_text(angle = 90, hjust = 0.5, vjust = 0))    
} 

@jonocarroll
Copy link
Owner

Is the argument just that easy_rotate_*_labels() should have better defaults? I can expose the vjust with a more friendly argument, but otherwise angle=90 is the default.

@davidhodge931
Copy link
Author

davidhodge931 commented Oct 30, 2024

Yeah, I think the best defaults are labels centred on the tick, and justified closest to the axis. I.e. like in my example code above.

But I don't know how that can be done for all angles, other than if you make a standalone 90 function.

Feel free to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants