Reputation: 107
I would like to change the vertical adjustment of individual tick mark labels in a plot. I've looked at the documentation on element_text
and at SO questions (this one was helpful) but they discuss hjust/vjust only as applied to all axis text. When I try to apply a vector of vjust values to axis text, the axis text font face changes and the distance between the axis text and the axis and the axis label change too. If someone can point me to documentation that explains this behavior, that would be much appreciated.
Here is a minimal example:
p <- ggplot(data = mtcars, aes(x=wt, y=mpg)) + geom_point()
p + theme(axis.text.x = element_text(vjust = c(0,-.5,0,0)))
Upvotes: 1
Views: 752
Reputation: 78792
You may need to settle for a workaround:
library(ggplot2)
p <- ggplot(data = mtcars, aes(x=wt, y=mpg))
p <- p + geom_point()
p <- p + scale_x_continuous(breaks=c(2:5),
labels=c("2", "\n3", "4\n", "\n\n5"))
p
Upvotes: 2