Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical spaces in legend

Tags:

graph

plot

r

legend

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"))

enter image description here

like image 924
RenatoRenatoRenato Avatar asked Jul 12 '16 14:07

RenatoRenatoRenato


People also ask

How do I reduce space between legends?

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.

What is legend in R studio?

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.


1 Answers

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.

like image 56
akraf Avatar answered Oct 15 '22 02:10

akraf