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"))
If you want to adjust the line space between lines in the legend, you can right-click the legend to select Properties... from the context menu to open the Text Object dialog. In the Text tab of this dialog, for the Line Spacing(%) item, select a value from the drop-down list or enter a value in the combo box directly.
A legend is defined as an area of the graph plot describing each of the parts of the plot. The legend plot is used to show statistical data in graphical form. Syntax: legend(x, y, legend, fill, col, bg, lty, cex, title, text.font, bg) Parameters: x and y: These are co-ordinates to be used to position the legend.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With