1

To make my graph presentable I'm trying to move the tick labels on the x-axis. I'd like to move the labels, so the don't run into the graph and over the data. My current code for the graph is as follows:

 ggplot(Duffel_plotdat, aes(Afkorting, est)) + geom_point() + geom_errorbar(aes(ymin=est-se, ymax=est+se)) + labs(title="Variance loggers for each AHS") + xlab("Artificial hibernation structures") + ylab("Variance") +
scale_x_discrete(breaks=c("BL","BW","H","K","MB","MCD","WK"),
                 labels=c("Loose in brick", "In brick closed\nwith cotton wool", "Square\nceiling box", "Wall logger\ndirectly on wall", "Wall logger\non wooden cube", "Middle of\nCD-rack", "Wall plate box")) +
  theme(axis.text.x = element_text(angle=45))

Giving this graph: Boxplot

I found another question on this topic (change the position (move) of tick labels when plotting with matplotlib) but since the figures are no longer available, I can't really determine if this helps me.

Finally I'd migth want to change the angle, so that the label names incline in the other way (diagonal from top left, to bottom right). I tried to do so using

angle=135 

making the angle rigth, but putting the text upside down.

Community
  • 1
  • 1
Mark
  • 43
  • 1
  • 7
  • You'll want to tinker with the `hjust` and/or `vjust` in `element_text`. Honestly, I can never remember the right combination to get the labels in the right spot, I always have to try 2-3 times before I get the right combo. – joran Sep 22 '16 at 15:41
  • You can try adjusting the offset via: http://stackoverflow.com/questions/14487188/increase-distance-between-text-and-title-on-the-y-axis – Lloyd Christmas Sep 22 '16 at 15:42
  • For angle, try -45 (or 315). For hjust and vjust, the right values will be somewhere between 0 and 1, but, like @joran, I can never remember the right combination. – eipi10 Sep 22 '16 at 15:43
  • Thanks both. vjust and using a negative value for angle worked perfectly. See answer for updated code and figure. – Mark Sep 23 '16 at 11:48

1 Answers1

3

Using the following code:

ggplot(Duffel_plotdat, aes(Afkorting, est)) + geom_point() + geom_errorbar(aes(ymin=est-se, ymax=est+se)) + labs(title="Variance loggers for each AHS") + xlab("Artificial hibernation structures") + ylab("Variance") +
scale_x_discrete(breaks=c("BL","BW","H","K","MB","MCD","WK"),
                 labels=c("Loose in brick", "In brick closed\nwith cotton wool", "Square\nceiling box", "Wall logger\ndirectly on wall", "Wall logger\non wooden cube", "Middle of\nCD-rack", "Wall plate box")) +
  theme(axis.text.x = element_text(vjust=0.6, angle=-45))

Gives the following figure: New Boxplot

eipi10
  • 91,525
  • 24
  • 209
  • 285
Mark
  • 43
  • 1
  • 7