R ggplot2 wrap long x-axis labels over multiple ro

2019-04-20 01:48发布

问题:

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?

回答1:

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.



标签: r ggplot2