Change the length of lines in a legend

The next simple example ...

plot(c(1,2),c(1,2),type="l")
legend(1,1.5,legend="Test",lty=1,seg.len=2)

      

... raises an error

Error in legend(1, 1.5, legend = "Test", lty = 1, seg.len = 2) : unused argument (seg.len = 2)

How to use seg.len

to get longer lines in legends?

+3


source to share


2 answers


If you use this in a larger script, other packages may mask the function legend()

. These "other" functions may not contain a parameter seg.len

. Thus, you have to reference the main function legend

. You can easily achieve this by adding a package like this:



graphics::legend(1, 1.5, legend = "Test", lty = 1, seg.len = 2)

      

+1


source


This code works fine for me (see image output below).

I suggest you do the following:



  • Download and install the latest R files. Load R
  • If you are using RStudio, download and install the most recent version. Download RStudio

enter image description here

0


source







All Articles