Skip to content

Instantly share code, notes, and snippets.

@ATpoint
Last active September 24, 2021 10:35
Show Gist options
  • Save ATpoint/66a3ef77c414b1278992309f841b5ab5 to your computer and use it in GitHub Desktop.
Save ATpoint/66a3ef77c414b1278992309f841b5ab5 to your computer and use it in GitHub Desktop.
No more messing with h/vjust when rotating labels
library(ggplot2)
library(reshape2)
library(egg)
# thanks to https://stackoverflow.com/questions/1330989/rotating-and-spacing-axis-labels-in-ggplot2/60650595#60650595
dat<-reshape2::melt(data.frame(groupA=rnorm(20),
groupB=rnorm(20),
groupC=rnorm(20)))
theme_set(theme_classic(base_size = 15))
plots <- lapply(c(0,22.5,45,90), function(angle){
ggplot(dat,aes(variable,value)) +
geom_boxplot() + xlab(element_blank()) +
guides(x = guide_axis(angle = angle)) ## this line is key
})
egg::ggarrange(plots[[1]],plots[[2]],
plots[[3]],plots[[4]],
ncol=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment