I am making a ggplot. The x-axis are factors, and the labels are long.
I can't shorten the labels, they're as short as they can be.
I am interested to make it so that labels are vertically offset. My preference would be to have every odd label at height 0, and every even at height 2 units more distant from the x-axis.
I have looked here, ggplot-hopeful-help, but have real trouble interpreting what is going on, and so can't make a useful version of this.
Any ideas??
(example code below... I'm not very good at formatting code here, it appears... sry.)
library("ggplot2");
stack <- data.frame(value =rnorm(n = 1000, sd = 2, mean=34)); stack$fact <- as.factor(rep(1:5, each=1000/5));
ggplot(stack, aes(x=fact, y=value)) + geom_boxplot(aes(fill=fact))+ scale_x_discrete(breaks=c("1", "2", "3", "4", "5"), labels=c("hi","don't suggest I shorten the text","I need long labels", "This is a long factor label","This label is very long"))
+ theme(axis.text.x = element_text(vjust = grid::unit(c(-2, 0), "points")))
where -2 will be for the odd labels and 0 for the even labels. – Didzis Elferts