Dear all I encountered strange behaviour of ggplot with combination of facet and subsetting. I use for creating plots sometimes a for cycle, something like this for (i in n:m) { p<-ggplot(data, aes(x=x, y=data[,i], colour=f))), ...} However I found strange result with this combination This is OK but only in BW p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) this is OK with colour p<-ggplot(vec.c, aes(x=fi, y=nad1mi, colour=as.factor(cas))) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) Here results in facets are mismatched p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2], colour=as.factor(cas))) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) and this is mismatched too p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) Doeas anybody know what I am doing wrong?> dput(vec.c)structure(list(cas = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), nad1mi = c(3, 2.7, 0.3, 0.5, 1.9, 5.3, 0.4, 3, 5.4, 0.7, 20.6, 16.7, 16.6, 20.7, 16.1, 15.2, 20.5, 16.4, 14.8, 24.6, 19.3, 15.2, 26.9, 21.3, 20.6, 22.6, 16.3, 15.7, 19.3, 16.5, 15.5, 3.6, 3.4, 5.9, 4.6, 5.4, 4.2, 5.3, 5.6, 5.1, 5), stroj = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("mastersizer", "odstredivka", "zetasizer"), class = "factor"), fi = c(341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L, 341L, 341L, 341L, 285L, 285L, 285L, 401L, 401L, 401L, 231L, 231L, 231L, 190L, 190L, 190L, 167L, 167L, 167L, 161L, 161L, 161L, 341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L )), .Names = c("cas", "nad1mi", "stroj", "fi"), class = "data.frame", row.names = c(1L, 2L, 6L, 7L, 11L, 12L, 16L, 17L, 21L, 22L, 26L, 27L, 28L, 32L, 33L, 34L, 38L, 39L, 40L, 44L, 45L, 46L, 50L, 51L, 52L, 56L, 57L, 58L, 62L, 63L, 64L, 68L, 69L, 73L, 74L, 78L, 79L, 83L, 84L, 88L, 89L))>Regards Petr> sessionInfo(package = NULL)R Under development (unstable) (2014-07-16 r66175) Platform: i386-w64-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech Republic.1250 [3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C [5] LC_TIME=Czech_Czech Republic.1250 attached base packages: [1] stats datasets utils grDevices graphics methods base other attached packages: [1] ggplot2_1.0.0 lattice_0.20-29 fun_1.0 loaded via a namespace (and not attached): [1] colorspace_1.2-4 digest_0.6.4 grid_3.2.0 gtable_0.1.2 [5] labeling_0.2 MASS_7.3-33 munsell_0.4.2 plyr_1.8.1 [9] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 [13] stringr_0.6.2 tools_3.2.0>________________________________ 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.
I am not quite sure what you want to achieve here, but you only have one factor column so shouldn't you be using facet_wrap(~stroj), perhaps with nrow or ncol parameters? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On November 26, 2014 5:40:07 AM PST, PIKAL Petr <petr.pikal at precheza.cz> wrote:>Dear all > >I encountered strange behaviour of ggplot with combination of facet and >subsetting. I use for creating plots sometimes a for cycle, something >like this > >for (i in n:m) { p<-ggplot(data, aes(x=x, y=data[,i], colour=f))), ...} > >However I found strange result with this combination > >This is OK but only in BW >p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) >p+geom_point(size=5)+geom_line()+facet_grid(.~ p<-ggplot(vec.c, aes(x=fi, y=nad1mi))p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) )> >this is OK with colour >p<-ggplot(vec.c, aes(x=fi, y=nad1mi, colour=as.factor(cas))) >p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > >Here results in facets are mismatched >p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2], colour=as.factor(cas))) >p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > >and this is mismatched too >p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) >p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > >Doeas anybody know what I am doing wrong? > >> dput(vec.c) >structure(list(cas = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, >0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, >1L, 2L, 0L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), > nad1mi = c(3, 2.7, 0.3, 0.5, 1.9, 5.3, 0.4, 3, 5.4, 0.7, > 20.6, 16.7, 16.6, 20.7, 16.1, 15.2, 20.5, 16.4, 14.8, 24.6, > 19.3, 15.2, 26.9, 21.3, 20.6, 22.6, 16.3, 15.7, 19.3, 16.5, >15.5, 3.6, 3.4, 5.9, 4.6, 5.4, 4.2, 5.3, 5.6, 5.1, 5), stroj >structure(c(3L, > 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("mastersizer", > "odstredivka", "zetasizer"), class = "factor"), fi = c(341L, > 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L, 341L, > 341L, 341L, 285L, 285L, 285L, 401L, 401L, 401L, 231L, 231L, > 231L, 190L, 190L, 190L, 167L, 167L, 167L, 161L, 161L, 161L, > 341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L >)), .Names = c("cas", "nad1mi", "stroj", "fi"), class = "data.frame", >row.names = c(1L, >2L, 6L, 7L, 11L, 12L, 16L, 17L, 21L, 22L, 26L, 27L, 28L, 32L, >33L, 34L, 38L, 39L, 40L, 44L, 45L, 46L, 50L, 51L, 52L, 56L, 57L, >58L, 62L, 63L, 64L, 68L, 69L, 73L, 74L, 78L, 79L, 83L, 84L, 88L, >89L)) >> > >Regards >Petr > >> sessionInfo(package = NULL) >R Under development (unstable) (2014-07-16 r66175) >Platform: i386-w64-mingw32/i386 (32-bit) > >locale: >[1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech >Republic.1250 >[3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C >[5] LC_TIME=Czech_Czech Republic.1250 > >attached base packages: >[1] stats datasets utils grDevices graphics methods base > >other attached packages: >[1] ggplot2_1.0.0 lattice_0.20-29 fun_1.0 > >loaded via a namespace (and not attached): > [1] colorspace_1.2-4 digest_0.6.4 grid_3.2.0 gtable_0.1.2 > [5] labeling_0.2 MASS_7.3-33 munsell_0.4.2 plyr_1.8.1 > [9] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 >[13] stringr_0.6.2 tools_3.2.0 >> > >________________________________ >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. >______________________________________________ >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.
Below John Kane Kingston ON Canada> This is OK but only in BW > p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj)Perhaps: p <- ggplot(vec.c, aes(x=fi, y=nad1mi, colour = stroj)) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj)> and this is mismatched too > p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj)I don'[ understand what you want here so cannot suggest anything ____________________________________________________________ Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account.
Dear Petr, You need to use aes_string() instead of aes(). The.cols <- colnames(data)[n:m] for (i in The.cols) { p<-ggplot(data, aes_string(x="x", y= i, colour="f"))), ...} Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 Thierry.Onkelinx at inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: R-help [mailto:r-help-bounces at r-project.org] Namens PIKAL Petr Verzonden: woensdag 26 november 2014 14:40 Aan: R help Onderwerp: [R] ggplot facet and subsetting Dear all I encountered strange behaviour of ggplot with combination of facet and subsetting. I use for creating plots sometimes a for cycle, something like this for (i in n:m) { p<-ggplot(data, aes(x=x, y=data[,i], colour=f))), ...} However I found strange result with this combination This is OK but only in BW p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) this is OK with colour p<-ggplot(vec.c, aes(x=fi, y=nad1mi, colour=as.factor(cas))) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) Here results in facets are mismatched p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2], colour=as.factor(cas))) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) and this is mismatched too p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) Doeas anybody know what I am doing wrong?> dput(vec.c)structure(list(cas = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), nad1mi = c(3, 2.7, 0.3, 0.5, 1.9, 5.3, 0.4, 3, 5.4, 0.7, 20.6, 16.7, 16.6, 20.7, 16.1, 15.2, 20.5, 16.4, 14.8, 24.6, 19.3, 15.2, 26.9, 21.3, 20.6, 22.6, 16.3, 15.7, 19.3, 16.5, 15.5, 3.6, 3.4, 5.9, 4.6, 5.4, 4.2, 5.3, 5.6, 5.1, 5), stroj = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("mastersizer", "odstredivka", "zetasizer"), class = "factor"), fi = c(341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L, 341L, 341L, 341L, 285L, 285L, 285L, 401L, 401L, 401L, 231L, 231L, 231L, 190L, 190L, 190L, 167L, 167L, 167L, 161L, 161L, 161L, 341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L )), .Names = c("cas", "nad1mi", "stroj", "fi"), class = "data.frame", row.names = c(1L, 2L, 6L, 7L, 11L, 12L, 16L, 17L, 21L, 22L, 26L, 27L, 28L, 32L, 33L, 34L, 38L, 39L, 40L, 44L, 45L, 46L, 50L, 51L, 52L, 56L, 57L, 58L, 62L, 63L, 64L, 68L, 69L, 73L, 74L, 78L, 79L, 83L, 84L, 88L, 89L))>Regards Petr> sessionInfo(package = NULL)R Under development (unstable) (2014-07-16 r66175) Platform: i386-w64-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech Republic.1250 [3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C [5] LC_TIME=Czech_Czech Republic.1250 attached base packages: [1] stats datasets utils grDevices graphics methods base other attached packages: [1] ggplot2_1.0.0 lattice_0.20-29 fun_1.0 loaded via a namespace (and not attached): [1] colorspace_1.2-4 digest_0.6.4 grid_3.2.0 gtable_0.1.2 [5] labeling_0.2 MASS_7.3-33 munsell_0.4.2 plyr_1.8.1 [9] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 [13] stringr_0.6.2 tools_3.2.0>________________________________ 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. ______________________________________________ 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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
Thank you Thierry Still I wonder why without facet_grid code for (i in n:m) { p<-ggplot(data, aes(x=x, y=data[,i], colour=f))), ...} works and with facet_grid does not. Best regards Petr> -----Original Message----- > From: ONKELINX, Thierry [mailto:Thierry.ONKELINX at inbo.be] > Sent: Thursday, November 27, 2014 9:29 AM > To: PIKAL Petr; R help > Subject: RE: ggplot facet and subsetting > > Dear Petr, > > You need to use aes_string() instead of aes(). > > The.cols <- colnames(data)[n:m] > for (i in The.cols) { p<-ggplot(data, aes_string(x="x", y= i, > colour="f"))), ...} > > Best regards, > > ir. Thierry Onkelinx > Instituut voor natuur- en bosonderzoek / Research Institute for Nature > and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality > Assurance Kliniekstraat 25 1070 Anderlecht Belgium > + 32 2 525 02 51 > + 32 54 43 61 85 > Thierry.Onkelinx at inbo.be > www.inbo.be > > To call in the statistician after the experiment is done may be no more > than asking him to perform a post-mortem examination: he may be able to > say what the experiment died of. > ~ Sir Ronald Aylmer Fisher > > The plural of anecdote is not data. > ~ Roger Brinner > > The combination of some data and an aching desire for an answer does > not ensure that a reasonable answer can be extracted from a given body > of data. > ~ John Tukey > > -----Oorspronkelijk bericht----- > Van: R-help [mailto:r-help-bounces at r-project.org] Namens PIKAL Petr > Verzonden: woensdag 26 november 2014 14:40 > Aan: R help > Onderwerp: [R] ggplot facet and subsetting > > Dear all > > I encountered strange behaviour of ggplot with combination of facet and > subsetting. I use for creating plots sometimes a for cycle, something > like this > > for (i in n:m) { p<-ggplot(data, aes(x=x, y=data[,i], colour=f))), ...} > > However I found strange result with this combination > > This is OK but only in BW > p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > this is OK with colour > p<-ggplot(vec.c, aes(x=fi, y=nad1mi, colour=as.factor(cas))) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > Here results in facets are mismatched > p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2], colour=as.factor(cas))) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > and this is mismatched too > p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > Doeas anybody know what I am doing wrong? > > > dput(vec.c) > structure(list(cas = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 0L, 1L, > 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, 2L, 0L, 1L, > 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), > nad1mi = c(3, 2.7, 0.3, 0.5, 1.9, 5.3, 0.4, 3, 5.4, 0.7, > 20.6, 16.7, 16.6, 20.7, 16.1, 15.2, 20.5, 16.4, 14.8, 24.6, > 19.3, 15.2, 26.9, 21.3, 20.6, 22.6, 16.3, 15.7, 19.3, 16.5, > 15.5, 3.6, 3.4, 5.9, 4.6, 5.4, 4.2, 5.3, 5.6, 5.1, 5), stroj > structure(c(3L, > 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("mastersizer", > "odstredivka", "zetasizer"), class = "factor"), fi = c(341L, > 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L, 341L, > 341L, 341L, 285L, 285L, 285L, 401L, 401L, 401L, 231L, 231L, > 231L, 190L, 190L, 190L, 167L, 167L, 167L, 161L, 161L, 161L, > 341L, 341L, 285L, 285L, 401L, 401L, 231L, 231L, 190L, 190L > )), .Names = c("cas", "nad1mi", "stroj", "fi"), class > "data.frame", row.names = c(1L, 2L, 6L, 7L, 11L, 12L, 16L, 17L, 21L, > 22L, 26L, 27L, 28L, 32L, 33L, 34L, 38L, 39L, 40L, 44L, 45L, 46L, 50L, > 51L, 52L, 56L, 57L, 58L, 62L, 63L, 64L, 68L, 69L, 73L, 74L, 78L, 79L, > 83L, 84L, 88L, > 89L)) > > > > Regards > Petr > > > sessionInfo(package = NULL) > R Under development (unstable) (2014-07-16 r66175) > Platform: i386-w64-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech > Republic.1250 [3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C > [5] LC_TIME=Czech_Czech Republic.1250 > > attached base packages: > [1] stats datasets utils grDevices graphics methods base > > other attached packages: > [1] ggplot2_1.0.0 lattice_0.20-29 fun_1.0 > > loaded via a namespace (and not attached): > [1] colorspace_1.2-4 digest_0.6.4 grid_3.2.0 gtable_0.1.2 > [5] labeling_0.2 MASS_7.3-33 munsell_0.4.2 plyr_1.8.1 > [9] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 > [13] stringr_0.6.2 tools_3.2.0 > > > > ________________________________________________________________ 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.
Thanks to John, Denis, Jeff and Thierry The key is to use aes_string instead of aes in cycle and preprocess objects to avoid creating factors on fly. For some reason, facet_grid does not accept [,], while without facet_grid such subsetting works without problem. I use such construction when I have big object and I want to make plot for each column for visual inspection. I usually populate pdf file with plots. Thanks again, problem solved, curiosity remains. Petr> -----Original Message----- > From: John Kane [mailto:jrkrideau at inbox.com] > Sent: Wednesday, November 26, 2014 6:13 PM > To: PIKAL Petr; R help > Subject: RE: [R] ggplot facet and subsetting > > Below > > John Kane > Kingston ON Canada > > This is OK but only in BW > > p<-ggplot(vec.c, aes(x=fi, y=nad1mi)) > > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > Perhaps: > p <- ggplot(vec.c, aes(x=fi, y=nad1mi, colour = stroj)) > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > > > and this is mismatched too > > p<-ggplot(vec.c, aes(x=fi, y=vec.c[,2])) > > p+geom_point(size=5)+geom_line()+facet_grid(.~stroj) > > I don'[ understand what you want here so cannot suggest anything > > ____________________________________________________________ > Can't remember your password? Do you need a strong and secure password? > Use Password manager! It stores your passwords & protects your account. > Check it out at http://mysecurelogon.com/password-manager >________________________________ 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.