R:增加绘图和轴标签之间的边距 [英] R: Increase margins between plot and axis labels

查看:67
本文介绍了R:增加绘图和轴标签之间的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个代码,无法弄清楚如何影响这个间距..我试过 oma、mai 等,但无法缩小这个空间(情节和轴描述2000 年 1 月"之间的空间)等等.).我需要哪个命令?

I'm working through a code and cannot figure out how to influence this spacing..I've tried oma, mai etc. but cannot get this space smaller (the space between the plot and the axis description "Jan 2000" etc.). Which command do I need?

推荐答案

我看到您提到您尝试过 oma 和 mai,但是您尝试过 mgp 吗?您可以使用 mgp.axis.labels 改变单个轴与其刻度标签之间的空间,这需要 Hmsic 包

I see you mention that you have tried oma and mai, but have you tried mgp? You can vary the space between an individual axis and its tick labels using mgp.axis.labels, which requires the Hmsic package

让我们设置一个示例数据框:

Let's set up an example dataframe:

require(Hmisc)
A <- rnorm(3,1,100)
B <- c("january","february","march")
dat <- data.frame(B,A)

options('mpg.axis.labels') 为每个轴提供 0.7 的默认距离

options('mpg.axis.labels') gives you the default distance of .7 for each axis

!> options('mgp.axis.labels')
 $mgp.axis.labels
 [1] 0.7 0.7

这为您提供了每个轴的 3 个值,在这种情况下,我们打印 x 轴的默认值:

This gives you the 3 values for each axis, in this case we print the x axis default values:

mgp.axis.labels(type='x')
 [1] 3.0 0.7 0.0

让我们将刻度标签和绘图之间的距离更改为原来的大约 1/3:

Let's change the distance between tick labels and plot to approximately 1/3rd of what it was:

mgp.axis.labels(c(3.0,0.2,0.0), type='x')

plot(dat,axes=FALSE)
mgp.axis(1,at=1:3,labels=dat$B)

完成!现在 X 轴和刻度标签之间的距离更小.

Done! There is now less distance between the X axis and the tick labels.

这篇关于R:增加绘图和轴标签之间的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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