更改 ggplot2 中轴文本的字体大小和方向 [英] Changing font size and direction of axes text in ggplot2

查看:37
本文介绍了更改 ggplot2 中轴文本的字体大小和方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一个图表,在 x 轴上有一个分类变量,在 y 轴上有一个数值变量.

I am plotting a graph with a categorical variable on the x axis and a numerical variable on the y axis.

对于 x 轴,鉴于有很多数据点,默认文本格式会导致每个刻度线的标签与其他标签重叠.我如何 (a) 更改我的轴文本的字体大小和 (b) 更改文本的方向,使文本垂直于轴?

For the x axis, given that there are many data points, the default text formatting causes the label for each tick mark to overlap with other labels. How do I (a) change the font size for my axis text and (b) change the orientation of the text so that the text is perpendicular to the axis?

推荐答案

使用theme():

d <- data.frame(x=gl(10, 1, 10, labels=paste("long text label ", letters[1:10])), y=rnorm(10))
ggplot(d, aes(x=x, y=y)) + geom_point() +
    theme(text = element_text(size=20),
        axis.text.x = element_text(angle=90, hjust=1)) 
#vjust adjust the vertical justification of the labels, which is often useful

此处有很多关于如何格式化 ggplot 的好信息.您可以使用 ?theme 查看可以修改的完整参数列表(基本上是所有参数).

There's lots of good information about how to format your ggplots here. You can see a full list of parameters you can modify (basically, all of them) using ?theme.

这篇关于更改 ggplot2 中轴文本的字体大小和方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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