【问题标题】:R, Change distance between axis tick marks and tick mark labelsR,更改轴刻度线和刻度线标签之间的距离
【发布时间】:2013-05-07 21:34:28
【问题描述】:

在以下示例中,我在 0.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)

这给出了:

我的自定义标签太接近常规标签(我也需要),我想让标签更接近刻度线。我看过了

help(par) 

如何使该标签更接近轴?

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

【问题讨论】:

    标签: r graphics


    【解决方案1】:

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

    编辑:使用mtext 而不是axis:

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

    【讨论】:

    • 谢谢! mtext 与 label=FALSE 的轴调用很好地结合使用,仍然可以获得刻度线。我使用 las=1 将所有标签设置为水平(当与 barplot 一起使用时,las=2 将 x 轴标签横向翻转)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多