【问题标题】:How to keep the space between tick and label minimum?如何保持刻度和标签之间的空间最小?
【发布时间】:2018-10-26 18:59:41
【问题描述】:

我在这里遇到了一个小问题,我想得到一些提示。

如何更改刻度和标签之间的间距? (用 1 和 2 表示)

我目前的结构如下:

par(mfrow=c(5,2),oma=c(0,0,2,0),las=1,mar=c(3,5,2,1),cex.lab=0.9, cex.axis=0.7)
plot(sapply(ERRORS.train.fast[[1]],mean),main="Pipe 63569",type="l", ylab="", xlab="",xaxt="n")
axis(1, at=1:29,labels=seq(2,30,1))
title(ylab= "RMSE (-)",line=3)
title(xlab= "K-Value",line=2)

非常感谢您的帮助!

干杯, 奥利

【问题讨论】:

    标签: r plot graph label


    【解决方案1】:

    您可以将padj 参数用于“调整垂直于阅读方向的每个刻度标签。”(来自?axis

    par(mfrow = c(1, 2))
    plot(1:5, axes = F)
    axis(1)
    
    plot(1:5, axes = F)
    axis(1, padj = -.75)
    

    不幸的是,不同轴的方向不同(因为文本的“向上”是相对的),因此要将标签移近刻度,您需要降低padj 值 表示水平轴,但 padj 值较高 表示垂直轴。

    如果您旋转标签(如垂直轴上的示例图所示),您将使用hadj 而不是padj。总的来说,我希望你想要这样的东西:

    plot(1:5, axes = F)
    axis(1, padj = -.75)
    axis(2, hadj = 0, las = 1)
    

    【讨论】:

      【解决方案2】:

      您可以使用mpg 标准。

      par(mfrow=c(1,2))
      plot(iris[,3:4], pch=20, col=rainbow(3)[iris$Species],
          ylab="", xlab="",xaxt="n")
      axis(1, at=1:7)
      plot(iris[,3:4], pch=20, col=rainbow(3)[iris$Species],
          ylab="", xlab="", xaxt="n")
      axis(1, at=1:7, mgp=c(0,0.5,0))
      

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 2015-10-28
        • 1970-01-01
        • 2011-02-27
        • 2014-08-03
        • 1970-01-01
        • 2010-12-09
        相关资源
        最近更新 更多