Anthony Hauser
Anthony Hauser

Reputation: 719

Space in legend between symbol and text in R

Is the a way to reduce the default space between a symbol and the related text in legend in R? I only found how to change space between legend items but not between symbol and text.

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

Upvotes: 3

Views: 4746

Answers (1)

Maurits Evers
Maurits Evers

Reputation: 50718

We can use parameter x.intersp inside legend to adjust the amount of white-space between legend symbol and text.

Here are a some examples:

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

Upvotes: 6

Related Questions