在ggplot2中旋转和间隔轴标签 [英] Rotating and spacing axis labels in ggplot2

查看:236
本文介绍了在ggplot2中旋转和间隔轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情节,其中x轴是一个标签很长的因素。虽然可能不是一个理想的可视化,但现在我想简单地将这些标签旋转为垂直。

 我已经用下面的代码计算了这部分内容,但正如您所看到的,这些标签并不完全可见。数据(钻石)
钻石$ cut < - paste(Super Dee-Duper,as.character(diamonds $ cut))
q < - qplot(cut,carat,data = diamonds,geom =boxplot)
q + opts(axis.text.x = theme_text(angle = -90))

解决方案

将最后一行更改为

  q + theme(axis.text.x = element_text(angle = 90,hjust = 1))

默认情况下,即使旋转,轴也会在文本的中心对齐。当你旋转+/- 90度时,你通常希望它在边缘对齐:

http://learnr.wordpress.com/2009/03/17/ggplot2-barplots/ =noreferrer>此博文。


I have a plot where the x-axis is a factor whose labels are long. While probably not an ideal visualization, for now I'd like to simply rotate these labels to be vertical. I've figured this part out with the code below, but as you can see, the labels aren't totally visible.

data(diamonds)
diamonds$cut <- paste("Super Dee-Duper",as.character(diamonds$cut))
q <- qplot(cut,carat,data=diamonds,geom="boxplot")
q + opts(axis.text.x=theme_text(angle=-90))

解决方案

Change the last line to

q + theme(axis.text.x = element_text(angle = 90, hjust = 1))

By default, the axes are aligned at the center of the text, even when rotated. When you rotate +/- 90 degrees, you usually want it to be aligned at the edge instead:

The image above is from this blog post.

这篇关于在ggplot2中旋转和间隔轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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