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

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

问题描述



对于x轴,假设有很多种类的图形,它们分别是x轴和c轴上的分类变量。数据点,默认的文本格式会使每个刻度标记的标签与其他标签重叠。我如何(a)更改我的轴文本的字体大小和(b)更改文本的方向以便文本垂直于轴?

解决方案使用 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调整标签的垂直对齐,通常很有用



有很多有关如何格式化您的ggplots 此处的详细信息。您可以使用?theme 来查看您可以修改的所有参数列表(基本上都是这些参数)。


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

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?

解决方案

Use 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

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天全站免登陆