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 different line 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]]
What do you want to change about the lines? pch (different characters) might give the desired variety. Michael On Tue, Feb 21, 2012 at 7:56 AM, Alaios <alaios at yahoo.com> wrote:> 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 different line 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. >
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 thesame 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 withdifferentline 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 tokeep> 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, andespecially> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On 02/21/2012 11:56 PM, Alaios wrote:> 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 different line 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. > >Hi Alex, The easiest way is to define a vector of more line types and then step through that vector. Here is one with the default five broken lines and five more that are reasonably distinguishable: mylinetypes=c("44", "13", "1343", "73", "2262","7272","5331","3366","2714","6224") plot(1:10,type="n") for(i in 1:10) abline(h=i,lty=mylinetypes[i]) Work out a way to generate different line types automatically? You might be able to do this by some tricky algorithm that applied a sequence like (+3,-2,+1,-1) to your index and then rotating the sequence on each iteration, BUT, your plot would still probably look like a mess with more than ten lines. Jim