Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid line type: must be length 2, 4, 6 or 8

Tags:

plot

r

I am using segments for drawing line but i need little bit more control on line type. SO I am using lty="1" but i get error message. I am using code below.

segments(593, 20.65+.06, 593+3, 20.65+.06, col= "black", lty="1")

But i am getting following error message.

  Error in segments(593, 20.65 + 0.06, 593 + 3, 20.65 + 0.06, col = "black",  : 
  invalid line type: must be length 2, 4, 6 or 8

I just need to control line type mentioned in lty().How can i fix this problem?

like image 586
Manish Avatar asked Aug 05 '13 01:08

Manish


2 Answers

You can fix it by reading ?par:

Line types can either be specified by giving an index into a small built-in table of line types (1 = solid, 2 = dashed, etc, see lty above) or directly as the lengths of on/off stretches of line. This is done with a string of an even number (up to eight) of characters, namely non-zero (hexadecimal) digits which give the lengths in consecutive positions in the string. For example, the string "33" specifies three units on followed by three off and "3313" specifies three units on followed by three off followed by one on and finally three off. The ‘units’ here are (on most devices) proportional to lwd, and with lwd = 1 are in pixels or points or 1/96 inch.

So, passing a character to lty doesn't mean what you thought. You probably just meant lty = 1.

like image 72
joran Avatar answered Sep 18 '22 02:09

joran


I came here with the same error message, while defining lty for multiple (3) lines:

legend(..., lty = c(1, "dashed", "dotdash"), ...)

This error is solved by defining all linetypes with the respective string key:

legend(..., lty = c("solid", "dashed", "dotdash"), ...)
like image 38
mrk Avatar answered Sep 19 '22 02:09

mrk