R

时间:2018-07-18 09:14:13

标签: r legend

是否可以减少R中图例中符号和相关文本之间的默认间距?我只找到了如何更改图例项之间的空间,而不是符号和文本之间的空间。

par(lwd=1,mai=c(0,0,0,0))
plot.new()
legend(x="left", inset =0,
         c("Simulated by the model"),
         lty=c(1,NA),pch=c(NA,"o"),lwd=c(2,3), col=c("black","red"), box.col=NA,horiz=TRUE,cex=1.5,text.width = c(0.3,0.3))

space between the line and the text

1 个答案:

答案 0 :(得分:1)

我们可以在图例中使用参数x.intersp来调整图例符号和文本之间的空白量。

以下是一些示例:

par(lwd = 1, mai = c(0,0,0,0), mfrow = c(2, 2))
prm <- c(0.1, 1.0, 2.0, 3.0)
for (i in 1:length(prm)) {
    plot.new()
    legend(
        x = "left",
        inset = 0,
        c(sprintf("x.intersp = %2.1f", prm[i])),
        lty = c(1, NA),
        pch = c(NA, "o"),
        lwd=c(2, 3),
        col = c("black", "red"),
        box.col = NA,
        horiz = TRUE,
        cex = 1.5,
        text.width = c(0.3, 0.3),
        x.intersp = prm[i])
}

enter image description here