ggeasy easy_rotate_x_labels doesn't work with grafify
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()
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.