[R] Plot Many Data to same plot

Petr PIKAL petr.pikal at precheza.cz
Tue Feb 21 16:50:57 CET 2012


Hi


If you want to have more than 6 line types you had either to use colours 
or to follow last part of lty advice from par and go to section "Line 
types". In that case you can not simúply use lty 1,2,...,n but you have to 
prespecify line types in some character vector and choose from that 
vector.

Quote
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. 

However with more than 6 lines in one colour the picture will probably 
resemble mad spider net.
Regards
Petr


r-help-bounces at r-project.org napsal dne 21.02.2012 13:56:53:

> Alaios <alaios at yahoo.com> 
> Odeslal: r-help-bounces at r-project.org
> 
> 21.02.2012 13:56
> 
> Odpovězte prosím uživateli
> Alaios <alaios at yahoo.com>
> 
> Komu
> 
> R help <R-help at r-project.org>
> 
> Kopie
> 
> Předmět
> 
> [R] Plot Many Data to same plot
> 
> Dear all,
> I have a function that for a variable number of inputs plots them to the 
same plot
> I am doing this quite simply by
> 
> plot(seq(from=start, to=stop, length.out=np), datalist[[1]]
> $dataset                                                 
>                  xlim=c(start, stop), ylim=c(0, 1), 
> 
type="l")                                                                                      
> 
                                                                                                                                                                                                     
>         if (length(datalist) > 1) 
> 
{                                                                                                                                                                  
>                 for (i in 2:length(datalist)) 
> 
{                                                                                                                                                      
>                         np <- length(datalist[[i]]
> 
$dataset)                                                                            
>                         lines(seq(from=start, to=stop, length.out=np), 
> datalist[[i]]$dataset$, lty=i)                                    
>                 
> 
}                                                                                                                                                                                    
>         }         
> 
> as you can see, specifically this line    
> 
>      lines(seq(from=start, to=stop, length.out=np), 
datalist[[i]]$dataset$
> lty=i)                                    
> 
> is changing the line type so any different input is plotted with 
differentline type.
> 
> This works quite well for 6 lines but if the arguments are more than 6 
(in
> my case 7) the line type starts from the beginning. Is it possible to 
keep
> that loop and have the lines produced in plots a bit more customized 
(like
> lines with squares and or cubes).
> 
> I have already checked in the ?par
> but I can not find how I can modify the line in that sense, and 
especially
> doing this smart inside a for loop.
> 
> 
> Could you please help me with that?
> I would like to thank you in advance for your help
> 
> Regards
> Alex
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list