R ggplot2在多行上包装长x轴标签 [英] R ggplot2 wrap long x-axis labels over multiple rows

查看:610
本文介绍了R ggplot2在多行上包装长x轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个条形图(我使用ggplot2,geom_bar),但x轴的标签太长且重叠。我想尽可能长时间保持它们,但我也希望它们是水平的(不是垂直的,也不是有角度的)。有什么方法可以将多个(至少两个)行的长标签包装起来? 解决方案

我不知道有什么方法直接通过 ggplot 。然而,你可以这样做:

  ggplot(data.frame(x = 1:10,y = 1:10) ,aes(x,y))+ 
geom_point()+
labs(x ='真正的长标签\\\
带有返回')

使用您的轴标签,使它们以您选择的长度缠绕。


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?

解决方案

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在多行上包装长x轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆