R,更改轴刻度线和刻度线标签之间的距离 [英] R, Change distance between axis tick marks and tick mark labels

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

问题描述

在下面的示例中,我在.95处绘制了一个自定义刻度线(根据Thomas的建议进行编辑以使标签水平):

In the following example, I plot a custom tick mark at .95 (edited to make labels horizontal as per Thomas' suggestion):

d = matrix(runif(40), ncol=4)
colnames(d) = c('a','b','c','d')

barplot(
    d,
    beside=T, 
    col=c('#CD4E3C', '#816DC3','#569340', '#A87929'), 
    ylim=c(0,1), 
    cex.axis=.80,
    main= 'Title',
    las=1

)

abline(h= 1:10/10, col = 'lightgray', lty=3)
axis(side=2, at=c(.95), cex.axis=.75, tck=-.01, las=1)
abline(h= .95, col = '#000000', lty=3)

哪个给:

我的自定义标签太接近常规标签了(我也需要),我想使标签更接近刻度线.我浏览了

My custom label is too close to the regular label (which I also need), and I'd like to bring the label closer to the tick mark. I looked through

help(par) 

如何使该标签更靠近轴?

How might a bring that label closer to the axis?

使刻度线标签水平放置会有所帮助,但是我仍然希望将标签缩进0.95以反映缩短的刻度线.

Making the tick mark labels horizontal helped, but I'd still like to indent the label for .95 to reflect the shortened tick mark.

推荐答案

快速解决方案是将las=2放入您的barplot()axis()调用中,以使标签水平,并使标签更加清晰.

Quick solution is to put las=2 in both your barplot() and axis() calls to make labels horizontal and they'll be clearer.

使用mtext代替axis:

mtext("0.95",2,.5,at=.95,las=2,cex=.75)

这篇关于R,更改轴刻度线和刻度线标签之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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