11

I have a bar chart (I used ggplot2, geom_bar), but the labels for x-axis are too long and overlap. I would like to keep them as long as they are, but I also would like them to be horizontally (not vertically, nor with an angle). Is there some way to wrap the long labels over multiple (at least two) rows?

Fanny
  • 310
  • 3
  • 4
  • 8

1 Answers1

8

I am not aware of a way through ggplot directly. However you can do something like this:

ggplot(data.frame(x=1:10, y=1:10), aes(x,y)) +
  geom_point() +
  labs(x='really long label \n with a return')

With your axis labels to make them wrap at a length you choose.

Justin
  • 42,475
  • 9
  • 93
  • 111
  • That works really great! I don't know why I didn't think of it myself.. Thanks! – Fanny Oct 20 '12 at 07:04
  • 4
    This approach is quick and convenient. For a more scaleable method, see http://stackoverflow.com/questions/21878974/auto-wrapping-of-labels-via-labeller-label-wrap-in-ggplot2 – PatrickT Dec 14 '14 at 05:19