Vertical spaces in legend

我是研究僧i 提交于 2019-12-20 12:34:01

问题


I am having trouble formatting my legend. I would like to increase the vertical space between each element of the legend.

I post the image it produces and the code so you can help me if you want.

This is the code relative to the legend:

par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 0), new = TRUE)
legend("right", c("$\\lambda < \\lambda_{cr}$ ", "$\\lambda < \\lambda_{cr}$", 
"$\\lambda = \\lambda_{cr}$ ", "$\\lambda = \\lambda_{cr}$ "), xpd = TRUE, 
inset = c(0,0), bty = "n", lty = c(1, 1, 1, 1), lwd=2, col = c("black","green4","red","blue"))


回答1:


When you consult the legend manual, for example by typing ?legend into your R console, you find

Arguments

...

x.intersp - character interspacing factor for horizontal (x) spacing.

y.intersp - the same for vertical (y) line distances.

To fix your legend, you could start with an interspacing factor of 2, so your legend call would become

legend("right", c(
    "$\\lambda < \\lambda_{cr}$ ",
    "$\\lambda < \\lambda_{cr}$",
    "$\\lambda = \\lambda_{cr}$ ",
    "$\\lambda = \\lambda_{cr}$ "
), xpd = TRUE, inset = c(0,0), bty = "n", lty = c(1, 1, 1, 1),
lwd=2, col = c("black","green4","red","blue"),
y.intersp=2)

If that gives you too much or too little space between the items, adjust the value accordingly.



来源:https://stackoverflow.com/questions/38332355/vertical-spaces-in-legend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!