1

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)))
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Ole
  • 107
  • 3
  • 7

1 Answers1

2

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

enter image description here

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • Thank you. This works as a workaround. It would still be nice to know if I'm using `vjust` in an unintended way or why it changes more than the justification. – Ole Jun 08 '16 at 16:19