Dear all I am stuck with output of some result. Sorry for not providing working example but res is quite a big list and I believe you are able to understand my problem. I have npks variable, which can be anything from 1 to let say 5. I get result called here res as a nested list with several components and I want to plot these components based on npks value. I got this far par(mfrow=c(npks,1)) # slit the device for (i in 1:npks) { plot(res[[i]]$x, res[[i]]$y, pch=20) if (i ==1) { #lines in case npks==1 lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)} if(i==2) { # lines in case npks ==2 lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3) lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3) } I can follow this further and expand lines plotting with ifs but it seems to me that there must be better solution I overlooked. Here is a structure of res> str(res)List of 2 $ :List of 15 ..$ intnr : int 1 ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... ..$ fit : num [1:153] 15.2 15.3 15.4 15.5 15.7 ... ..$ fitpk : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ... ..$ basl : num [1:153] 258 258 258 258 258 ... ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ... ..$ rss : num 1354 ..$ num.ker: int 1 ..$ par : num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ... ..$ parbl : Named num [1:2] 12.86 -4.09 .. ..- attr(*, "names")= chr [1:2] "" "2485" ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ... ..$ accept : logi FALSE ..$ alpha : num 0.1 ..$ thresh : Named num 3.81 .. ..- attr(*, "names")= chr "90%" $ :List of 15 ..$ intnr : int 1 ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... ..$ fit : num [1:153] 15 15 15.1 15.1 15.2 ... ..$ fitpk : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ... ..$ basl : num [1:153] 258 258 258 258 258 ... ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ... ..$ rss : num 1325 ..$ num.ker: num 2 ..$ par : num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ... ..$ parbl : Named num [1:2] 12.86 -9.42 .. ..- attr(*, "names")= chr [1:2] "" "2485" ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ... .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ... ..$ accept : logi FALSE ..$ alpha : num 0.1 ..$ thresh : Named num 3.81 .. ..- attr(*, "names")= chr "90%">Best Regards Petr ________________________________ Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m. Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu. Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat. Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu. V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?: - vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu. - a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou. - trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech. - odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
Hi, Petr, from your example it's not doubtlessly clear to me sure how the sequence of ifs should really be continued, but couldn't a nested loop help? Something like: for (i in 1:npks) { plot(res[[i]]$x, res[[i]]$y, pch=20) for (j in 1:i) { lines(res[[i]]$x, res[[i]]$fitpk[j,], col=j, lwd=3)} } } (However, this seems too simple ...) Hth -- Gerrit On Tue, 15 Dec 2015, PIKAL Petr wrote:> Dear all > > I am stuck with output of some result. Sorry for not providing working > example but res is quite a big list and I believe you are able to > understand my problem. > > I have npks variable, which can be anything from 1 to let say 5. > > I get result called here res as a nested list with several components > and I want to plot these components based on npks value. I got this far > > par(mfrow=c(npks,1)) # slit the device > for (i in 1:npks) { > plot(res[[i]]$x, res[[i]]$y, pch=20) > > if (i ==1) { #lines in case npks==1 > lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)} > > if(i==2) { # lines in case npks ==2 > lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3) > lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3) > } > > I can follow this further and expand lines plotting with ifs but it > seems to me that there must be better solution I overlooked. > > Here is a structure of res > >> str(res) > List of 2 > $ :List of 15 > ..$ intnr : int 1 > ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... > .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... > ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... > ..$ fit : num [1:153] 15.2 15.3 15.4 15.5 15.7 ... > ..$ fitpk : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ... > ..$ basl : num [1:153] 258 258 258 258 258 ... > ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ... > ..$ rss : num 1354 > ..$ num.ker: int 1 > ..$ par : num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ... > ..$ parbl : Named num [1:2] 12.86 -4.09 > .. ..- attr(*, "names")= chr [1:2] "" "2485" > ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993 > .. ..- attr(*, "dimnames")=List of 2 > .. .. ..$ : NULL > .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ... > ..$ accept : logi FALSE > ..$ alpha : num 0.1 > ..$ thresh : Named num 3.81 > .. ..- attr(*, "names")= chr "90%" > $ :List of 15 > ..$ intnr : int 1 > ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... > .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... > ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... > ..$ fit : num [1:153] 15 15 15.1 15.1 15.2 ... > ..$ fitpk : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ... > ..$ basl : num [1:153] 258 258 258 258 258 ... > ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ... > ..$ rss : num 1325 > ..$ num.ker: num 2 > ..$ par : num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ... > ..$ parbl : Named num [1:2] 12.86 -9.42 > .. ..- attr(*, "names")= chr [1:2] "" "2485" > ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ... > .. ..- attr(*, "dimnames")=List of 2 > .. .. ..$ : NULL > .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ... > ..$ accept : logi FALSE > ..$ alpha : num 0.1 > ..$ thresh : Named num 3.81 > .. ..- attr(*, "names")= chr "90%" >> > > Best Regards > Petr
Hi Gerrit, Thanks, I tried it and it seems to be viable option. I knew I overlooked something pretty simple. Cheers Petr> -----Original Message----- > From: Gerrit Eichner [mailto:Gerrit.Eichner at math.uni-giessen.de] > Sent: Tuesday, December 15, 2015 12:31 PM > To: PIKAL Petr > Cc: r-help at r-project.org > Subject: Re: [R] plot several lines programmaticaly > > Hi, Petr, > > from your example it's not doubtlessly clear to me sure how the > sequence of ifs should really be continued, but couldn't a nested loop > help? > Something like: > > for (i in 1:npks) { > plot(res[[i]]$x, res[[i]]$y, pch=20) > > for (j in 1:i) { > lines(res[[i]]$x, res[[i]]$fitpk[j,], col=j, lwd=3)} > } > } > > (However, this seems too simple ...) > > Hth -- Gerrit > > > On Tue, 15 Dec 2015, PIKAL Petr wrote: > > > Dear all > > > > I am stuck with output of some result. Sorry for not providing > working > > example but res is quite a big list and I believe you are able to > > understand my problem. > > > > I have npks variable, which can be anything from 1 to let say 5. > > > > I get result called here res as a nested list with several components > > and I want to plot these components based on npks value. I got this > > far > > > > par(mfrow=c(npks,1)) # slit the device for (i in 1:npks) { > > plot(res[[i]]$x, res[[i]]$y, pch=20) > > > > if (i ==1) { #lines in case npks==1 > > lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)} > > > > if(i==2) { # lines in case npks ==2 > > lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3) lines(res[[i]]$x, > > res[[i]]$fitpk[i,], col=i, lwd=3) } > > > > I can follow this further and expand lines plotting with ifs but it > > seems to me that there must be better solution I overlooked. > > > > Here is a structure of res > > > >> str(res) > > List of 2 > > $ :List of 15 > > ..$ intnr : int 1 > > ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... > > .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... > > ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... > > ..$ fit : num [1:153] 15.2 15.3 15.4 15.5 15.7 ... > > ..$ fitpk : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ... > > ..$ basl : num [1:153] 258 258 258 258 258 ... > > ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ... > > ..$ rss : num 1354 > > ..$ num.ker: int 1 > > ..$ par : num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ... > > ..$ parbl : Named num [1:2] 12.86 -4.09 .. ..- attr(*, "names")> > chr [1:2] "" "2485" > > ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993 .. > ..- > > attr(*, "dimnames")=List of 2 .. .. ..$ : NULL .. .. ..$ : chr > [1:5] > > "loc" "height" "intens" "FWHM" ... > > ..$ accept : logi FALSE > > ..$ alpha : num 0.1 > > ..$ thresh : Named num 3.81 > > .. ..- attr(*, "names")= chr "90%" > > $ :List of 15 > > ..$ intnr : int 1 > > ..$ x : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ... > > .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ... > > ..$ y : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ... > > ..$ fit : num [1:153] 15 15 15.1 15.1 15.2 ... > > ..$ fitpk : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ... > > ..$ basl : num [1:153] 258 258 258 258 258 ... > > ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ... > > ..$ rss : num 1325 > > ..$ num.ker: num 2 > > ..$ par : num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ... > > ..$ parbl : Named num [1:2] 12.86 -9.42 .. ..- attr(*, "names")> > chr [1:2] "" "2485" > > ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ... > > .. ..- attr(*, "dimnames")=List of 2 > > .. .. ..$ : NULL > > .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ... > > ..$ accept : logi FALSE > > ..$ alpha : num 0.1 > > ..$ thresh : Named num 3.81 > > .. ..- attr(*, "names")= chr "90%" > >> > > > > Best Regards > > Petr________________________________ Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m. Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu. Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat. Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu. V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?: - vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu. - a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou. - trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech. - odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.