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

ggeasy easy_rotate_x_labels doesn't work with grafify #81

Open
Rohit-Satyam opened this issue Jan 23, 2025 · 1 comment
Open

ggeasy easy_rotate_x_labels doesn't work with grafify #81

Rohit-Satyam opened this issue Jan 23, 2025 · 1 comment

Comments

@Rohit-Satyam
Copy link

Hi @jonocarroll

I have been helped innumerable times by your package and I recommend it to every next person who works in R. While delivering a workshop, I tried to combine grafify output which is a ggobject and easy_remove_legend function. However, I realized it doesn't work as expected. Can you kindly investigate this and fix if this is a bug?

library(grafify)
library(dplyr)
sample3 <- read.csv("sample3.csv")

colnames(sample3) <- c("Group","Cycle","perc_parasitemia")
plot_scatterbar_sd(data = sample3, #data table
                   xcol = Group,      #X variable
                   ycol = perc_parasitemia,  facet = Cycle ,       #Y variable
                   fontsize = 15)+ggeasy::easy_remove_legend()+xlab("Cycle")+ylab("% Parasitemia")+ggeasy::easy_rotate_x_labels()

temp.csv

@Rohit-Satyam Rohit-Satyam changed the title ggeasy rotal x label doesn't work with grafify ggeasy easy_rotate_x_labels doesn't work with grafify Jan 23, 2025
@jonocarroll
Copy link
Owner

Hi, thanks for the feedback; I'm glad you've found the package helpful.

It looks like this is less a bug and more an edge case based on how {grafify} builds the plot.

If I build the plot as you presented

p <- plot_scatterbar_sd(data = sample3,
                        xcol = Group,
                        ycol = perc_parasitemia,  
                        facet = Cycle,
                        fontsize = 15) +
  ggeasy::easy_remove_legend() + 
  xlab("Cycle") + 
  ylab("% Parasitemia") + 
  ggeasy::easy_rotate_x_labels()

Then {ggeasy} doesn't change the angle

p

{ggeasy} is essentially a set of shortcuts to theme() commands (which are presented when you add teach = TRUE); trying to implement this manually changes the colour, but not the angle

p + theme(axis.text.x = element_text(colour = "red", angle = 90))

As it turns out, the text angle is controlled via the guide_axis() for {grafify} plots, which isn't what {ggeasy} is trying to change

p + guides(x = guide_axis(angle = 90))

A more consistent way seems to be to add the angle to the {grafify} call as TextXAngle, which internally is passed to guide_axis()

p2 <- plot_scatterbar_sd(data = sample3,
                         xcol = Group,
                         ycol = perc_parasitemia,  
                         facet = Cycle,
                         fontsize = 15,
                         TextXAngle = 90) +
  ggeasy::easy_remove_legend() + 
  xlab("Cycle") + 
  ylab("% Parasitemia") 
p2

In theory we could additionally check for a guide_axis and also wrap that, but it somewhat falls outside of our scope of 'shortcuts to theme commands' and risks changing things in unexpected ways.

I hope that resolves your issue.

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