1

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

Anthony Hauser
  • 619
  • 1
  • 5
  • 13
  • Please provide some sample code and data which will help us understand your problem better. – radmuzom Jul 18 '18 at 09:17
  • See the edited question – Anthony Hauser Jul 18 '18 at 09:34
  • @AnthonyHauser We need sample data and code to reproduce the/a plot. At the moment it's not even clear how you generate your plots: base R plotting, using `ggplot`, `lattice`, ...? Please review how to provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Maurits Evers Jul 18 '18 at 09:47

1 Answers1

4

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

Maurits Evers
  • 45,165
  • 4
  • 35
  • 59