简体   繁体   English

R,改变轴刻度线和刻度线标签之间的距离

[英]R, Change distance between axis tick marks and tick mark labels

In the following example, I plot a custom tick mark at .95 (edited to make labels horizontal as per Thomas' suggestion): 在下面的示例中,我在.95处绘制自定义刻度标记(根据Thomas的建议进行编辑以使标签水平):

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)

Which gives: 这使:

在此输入图像描述

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? 如何使标签更靠近轴?

EDIT: Making the tick mark labels horizontal helped, but I'd still like to indent the label for .95 to reflect the shortened tick mark. 编辑:使刻度线标签水平帮助,但我仍然希望缩进.95的标签以反映缩短的刻度线。

Quick solution is to put las=2 in both your barplot() and axis() calls to make labels horizontal and they'll be clearer. 快速解决方案是在barplot()axis()调用中放置las=2以使标签处于水平状态并且它们barplot()清晰。

EDIT: Use mtext instead of axis : 编辑:使用mtext而不是axis

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM