Re: [R] Labels on a pyramide
On 02/14/2010 01:27 AM, Orvalho Augusto wrote: I am using pyramid.plot() from the plotrix package. ... The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Bueno troglodita, You have discovered a deficiency in pyramid.plot, and for that you get an answer to your question and brand new source code! source(pyramid.plot.R) after loading the plotrix package. Use it quickly, for it will be in the next version of plotrix and then everyone (todo el mundo, hombre!) will be using it. Jim # it must be wider than the default to accommodate the long labels x11(width=10) par(mar=pyramid.plot(dados$masfr,dados$femfr, laxlab=c(0,10,20,30,40),raxlab=c(0,10,20,30,40), main=Primeiras 10 cancros mais frequentes por sexo, top.labels=c(Masculino, Tipo de cancro, Feminino), labels=dados[,c(maslab,femlab)], xycol=rep(#ff,10),xxcol=rep(#ff88ff,10), gap=25)) pyramid.plot-function(xy,xx,labels=NA,top.labels=c(Male,Age,Female), main=,laxlab=NULL,raxlab=NULL,unit=%,xycol,xxcol,gap=1, labelcex=1,mark.cat=NA,add=FALSE) { if(any(c(xy,xx)0)) stop(Negative quantities not allowed) xydim-dim(xy) if(length(labels)==1) labels-1:xydim[1] ncats-ifelse(is.null(dim(labels)),length(labels),length(labels[,1])) if(is.null(xydim)) { if(length(xy) != ncats || length(xx) != ncats) stop(xy, xx and labels must all be the same length) halfwidth-ceiling(max(c(xy,xx)))+gap } else { if(length(xy[,1]) != ncats || length(xx[,1]) != ncats) stop(xy, xx and labels must all be the same length) halfwidth-ceiling(max(c(rowSums(xy),rowSums(xx+gap } oldmar-par(mar) if(!add) { par(mar=c(4,2,4,2)) plot(0,xlim=c(-halfwidth,halfwidth),ylim=c(0,ncats+1), type=n,axes=FALSE,xlab=,ylab=,xaxs=i,yaxs=i,main=main) if(is.null(laxlab)) { laxlab-seq(halfwidth-gap,0,by=-1) axis(1,at=-halfwidth:-gap,labels=laxlab) } else axis(1,at=-(laxlab+gap),labels=laxlab) if(is.null(raxlab)) { raxlab-0:(halfwidth-gap) axis(1,at=gap:halfwidth,labels=raxlab) } else axis(1,at=raxlab+gap,labels=raxlab) axis(2,at=1:ncats,labels=rep(,ncats),pos=gap,tcl=-0.25) axis(4,at=1:ncats,labels=rep(,ncats),pos=-gap,tcl=-0.25) if(!is.na(mark.cat)) boxed.labels(0,mark.cat,labels[mark.cat]) if(is.null(dim(labels))) text(0,1:ncats,labels,cex=labelcex) else { text(-gap*0.9,1:ncats,labels[,1],cex=labelcex,adj=0) text(gap*0.9,1:ncats,labels[,2],cex=labelcex,adj=1) } mtext(top.labels,3,0,at=c(-halfwidth/2,0,halfwidth/2), adj=0.5,cex=labelcex) mtext(c(unit,unit),1,2,at=c(-halfwidth/2,halfwidth/2)) } if(is.null(xydim)) { if(missing(xycol)) xycol-rainbow(ncats) if(missing(xxcol)) xxcol-rainbow(ncats) rect(-(xy+gap),1:ncats-0.4,rep(-gap,ncats),1:ncats+0.4,col=xycol) rect(rep(gap,ncats),1:ncats-0.4,(xx+gap),1:ncats+0.4,col=xxcol) } else { if(missing(xycol)) xycol-rainbow(xydim[2]) if(missing(xxcol)) xxcol-rainbow(xydim[2]) xystart-xxstart-rep(gap,ncats) for(i in 1:xydim[2]) { xycolor-rep(xycol[i],ncats) xxcolor-rep(xxcol[i],ncats) rect(-(xy[,i]+xystart),1:ncats-0.4,-xystart,1:ncats+0.4, col=xycolor) rect(xxstart,1:ncats-0.4,xx[,i]+xxstart,1:ncats+0.4, col=xxcolor) xystart-xy[,i]+xystart xxstart-xx[,i]+xxstart } } return(oldmar) } __ R-help@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.
Re: [R] Labels on a pyramide
Jim thanks for your great! I will try to use your source code. Caveman Ps: Reconheco a minha trogolodice e por isso pedi ajuda. Lamento perturbar a todos por isso. On Sun, Feb 14, 2010 at 1:05 PM, Jim Lemon j...@bitwrit.com.au wrote: On 02/14/2010 01:27 AM, Orvalho Augusto wrote: I am using pyramid.plot() from the plotrix package. ... The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Bueno troglodita, You have discovered a deficiency in pyramid.plot, and for that you get an answer to your question and brand new source code! source(pyramid.plot.R) after loading the plotrix package. Use it quickly, for it will be in the next version of plotrix and then everyone (todo el mundo, hombre!) will be using it. Jim # it must be wider than the default to accommodate the long labels x11(width=10) par(mar=pyramid.plot(dados$masfr,dados$femfr, laxlab=c(0,10,20,30,40),raxlab=c(0,10,20,30,40), main=Primeiras 10 cancros mais frequentes por sexo, top.labels=c(Masculino, Tipo de cancro, Feminino), labels=dados[,c(maslab,femlab)], xycol=rep(#ff,10),xxcol=rep(#ff88ff,10), gap=25)) -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ R-help@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.
Re: [R] Labels on a pyramide
Pardon my ignorance here. The Jim code works. But the problem the text comes over the plot. Adjusting the laxlab and raxlab, to get more plot are, the text keeps being cut. And one more thing that might be added as a new functionality is an option to show the value of the bar. Thanks for your help Caveman On Sun, Feb 14, 2010 at 1:05 PM, Jim Lemon j...@bitwrit.com.au wrote: On 02/14/2010 01:27 AM, Orvalho Augusto wrote: I am using pyramid.plot() from the plotrix package. ... The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Bueno troglodita, You have discovered a deficiency in pyramid.plot, and for that you get an answer to your question and brand new source code! source(pyramid.plot.R) after loading the plotrix package. Use it quickly, for it will be in the next version of plotrix and then everyone (todo el mundo, hombre!) will be using it. Jim # it must be wider than the default to accommodate the long labels x11(width=10) par(mar=pyramid.plot(dados$masfr,dados$femfr, laxlab=c(0,10,20,30,40),raxlab=c(0,10,20,30,40), main=Primeiras 10 cancros mais frequentes por sexo, top.labels=c(Masculino, Tipo de cancro, Feminino), labels=dados[,c(maslab,femlab)], xycol=rep(#ff,10),xxcol=rep(#ff88ff,10), gap=25)) -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ R-help@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.
[R] Labels on a pyramide
I am using pyramid.plot() from the plotrix package. I have something like this xy.pop-dados$masfr xx.pop-dados$femfr #agelabels-dados$femlab xycol-color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),11) xxcol-color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1),11) xylab-dados$maslab xxlab-dados$femlab agelabels-xylab png(piramide9808.png) par(mar=pyramid.plot(xy.pop,xx.pop,labels=agelabels,top.labels=c(Masculino,,Feminino), main=Primeiras 10 cancros mais frequentes por sexo...,xycol=xycol,xxcol=xxcol,gap=0, labelcex=0)) dev.off() # the dados a dataframe fabircated by someother program and looks like: ## ordem femlab femfa femfr maslab masfa masfr 1 Colo do utero 258 26.76348548 Prostata613 43.81701215 2 Mama110 11.41078838 Figado 84 6.004288778 3 Esofago 62 6.43153527 Pele70 5.003573981 4 Figado 60 6.22406639 Sarcoma de Kaposi 65 4.64617584 5 Pele48 4.979253112 Esofago 63 4.503216583 6 Bexiga 37 3.838174274 Pulmao 46 3.288062902 7 Corpo do utero 34 3.526970954 Bexiga 43 3.073624017 8 Utero, SOE28 2.904564315 Penis 33 2.358827734 9 Sarcoma de Kaposi 28 2.904564315 Laringe 27 1.929949964 10 Vulva e Vagina 24 2.489626556 Colon 24 1.715511079 11 Outras localizacoes 275 28.52697095 Outras localizacoes 331 23.65975697 # The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Can some one help please? Caveman -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ R-help@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.
Re: [R] Labels on a pyramide
I took a shot at getting assymetric lableling but it's by no means perfect. You really, really ,really, should learn to offer data with dput. See below: On Feb 13, 2010, at 9:27 AM, Orvalho Augusto wrote: I am using pyramid.plot() from the plotrix package. I have something like this xy.pop-dados$masfr xx.pop-dados$femfr #agelabels-dados$femlab xycol-color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),11) xxcol-color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1), 11) xylab-dados$maslab xxlab-dados$femlab agelabels-xylab png(piramide9808.png) par (mar = pyramid .plot (xy .pop,xx.pop,labels=agelabels,top.labels=c(Masculino,,Feminino), main=Primeiras 10 cancros mais frequentes por sexo...,xycol=xycol,xxcol=xxcol,gap=0, labelcex=0)) dev.off() # the dados a dataframe fabircated by someother program and looks like: ## ordem femlab femfa femfr maslab masfa masfr 1 Colo do utero 258 26.76348548 Prostata613 43.81701215 2 Mama110 11.41078838 Figado 84 6.004288778 3 Esofago 62 6.43153527 Pele70 5.003573981 4 Figado 60 6.22406639 Sarcoma de Kaposi 65 4.64617584 5 Pele48 4.979253112 Esofago 63 4.503216583 6 Bexiga 37 3.838174274 Pulmao 46 3.288062902 7 Corpo do utero 34 3.526970954 Bexiga 43 3.073624017 8 Utero, SOE 28 2.904564315 Penis 33 2.358827734 9 Sarcoma de Kaposi 28 2.904564315 Laringe 27 1.929949964 10 Vulva e Vagina 24 2.489626556 Colon 24 1.715511079 11 Outras localizacoes 275 28.52697095 Outras localizacoes 331 23.65975697 In case anyone wants to take a crack at this without the hassle of recreating htis dataset... dput(dados) can be used to recreate the complete dataframe dados - structure(list(ordem = 1:11, femlab = structure(c(2L, 6L, 4L, 5L, 8L, 1L, 3L, 10L, 9L, 11L, 7L), .Label = c(Bexiga, Colo do utero, Corpo do utero, Esofago, Figado, Mama, Outras localizacoes, Pele, Sarcoma de Kaposi, Utero SOE, Vulva e Vagina), class = factor), femfa = c(258L, 110L, 62L, 60L, 48L, 37L, 34L, 28L, 28L, 24L, 275L), femfr = c(26.76348548, 11.41078838, 6.43153527, 6.22406639, 4.979253112, 3.838174274, 3.526970954, 2.904564315, 2.904564315, 2.489626556, 28.52697095), maslab = structure(c(9L, 4L, 7L, 11L, 3L, 10L, 1L, 8L, 5L, 2L, 6L), .Label = c(Bexiga, Colon, Esofago, Figado, Laringe, Outras localizacoes, Pele, Penis, Prostata, Pulmao, Sarcoma de Kaposi ), class = factor), masfa = c(613L, 84L, 70L, 65L, 63L, 46L, 43L, 33L, 27L, 24L, 331L), masfr = c(43.81701215, 6.004288778, 5.003573981, 4.64617584, 4.503216583, 3.288062902, 3.073624017, 2.358827734, 1.929949964, 1.715511079, 23.65975697)), .Names = c(ordem, femlab, femfa, femfr, maslab, masfa, masfr), class = data.frame, row.names = c(NA, -11L)) xy.pop-dados$masfr xx.pop-dados$femfr #agelabels-paste(dados$femlab, \t\t\t, dados$maslab, sep='') xycol-color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),11) xxcol-color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1),11) #xylab-dados$maslab #xxlab-dados$femlab #agelabels-xylab par(mar=pyramid.plot(xy.pop, xx.pop, labels= rep(,length(xy.pop)), top.labels=c(Masculino, , Feminino), main=Primeiras 10 cancros mais frequentes por sexo..., xycol=xycol,xxcol=xxcol, gap=0)) text(-xy.pop-5*nchar(dados$maslab), 1:length(xy.pop), dados $maslab );text(xx.pop+7*nchar(dados$femlab), 1:length(xx.pop), dados $femlab ) # Could not get the right ratio of xx.pop to nchar to get completely correct placement and given the small number you might just want to put in a hand-crafted vector, # The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Can some one help please? Caveman -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.
Re: [R] Labels on a pyramide
This is good! Yes I must learn about dput. Thank you Caveman On Sat, Feb 13, 2010 at 6:57 PM, David Winsemius dwinsem...@comcast.net wrote: I took a shot at getting assymetric lableling but it's by no means perfect. You really, really ,really, should learn to offer data with dput. See below: On Feb 13, 2010, at 9:27 AM, Orvalho Augusto wrote: I am using pyramid.plot() from the plotrix package. I have something like this xy.pop-dados$masfr xx.pop-dados$femfr #agelabels-dados$femlab xycol-color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),11) xxcol-color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1),11) xylab-dados$maslab xxlab-dados$femlab agelabels-xylab png(piramide9808.png) par(mar=pyramid.plot(xy.pop,xx.pop,labels=agelabels,top.labels=c(Masculino,,Feminino), main=Primeiras 10 cancros mais frequentes por sexo...,xycol=xycol,xxcol=xxcol,gap=0, labelcex=0)) dev.off() # the dados a dataframe fabircated by someother program and looks like: ## ordem femlab femfa femfr maslab masfa masfr 1 Colo do utero 258 26.76348548 Prostata 613 43.81701215 2 Mama 110 11.41078838 Figado 84 6.004288778 3 Esofago 62 6.43153527 Pele 70 5.003573981 4 Figado 60 6.22406639 Sarcoma de Kaposi 65 4.64617584 5 Pele 48 4.979253112 Esofago 63 4.503216583 6 Bexiga 37 3.838174274 Pulmao 46 3.288062902 7 Corpo do utero 34 3.526970954 Bexiga 43 3.073624017 8 Utero, SOE 28 2.904564315 Penis 33 2.358827734 9 Sarcoma de Kaposi 28 2.904564315 Laringe 27 1.929949964 10 Vulva e Vagina 24 2.489626556 Colon 24 1.715511079 11 Outras localizacoes 275 28.52697095 Outras localizacoes 331 23.65975697 In case anyone wants to take a crack at this without the hassle of recreating htis dataset... dput(dados) can be used to recreate the complete dataframe dados - structure(list(ordem = 1:11, femlab = structure(c(2L, 6L, 4L, 5L, 8L, 1L, 3L, 10L, 9L, 11L, 7L), .Label = c(Bexiga, Colo do utero, Corpo do utero, Esofago, Figado, Mama, Outras localizacoes, Pele, Sarcoma de Kaposi, Utero SOE, Vulva e Vagina), class = factor), femfa = c(258L, 110L, 62L, 60L, 48L, 37L, 34L, 28L, 28L, 24L, 275L), femfr = c(26.76348548, 11.41078838, 6.43153527, 6.22406639, 4.979253112, 3.838174274, 3.526970954, 2.904564315, 2.904564315, 2.489626556, 28.52697095), maslab = structure(c(9L, 4L, 7L, 11L, 3L, 10L, 1L, 8L, 5L, 2L, 6L), .Label = c(Bexiga, Colon, Esofago, Figado, Laringe, Outras localizacoes, Pele, Penis, Prostata, Pulmao, Sarcoma de Kaposi ), class = factor), masfa = c(613L, 84L, 70L, 65L, 63L, 46L, 43L, 33L, 27L, 24L, 331L), masfr = c(43.81701215, 6.004288778, 5.003573981, 4.64617584, 4.503216583, 3.288062902, 3.073624017, 2.358827734, 1.929949964, 1.715511079, 23.65975697)), .Names = c(ordem, femlab, femfa, femfr, maslab, masfa, masfr), class = data.frame, row.names = c(NA, -11L)) xy.pop-dados$masfr xx.pop-dados$femfr #agelabels-paste(dados$femlab, \t\t\t, dados$maslab, sep='') xycol-color.gradient(c(0,0,0.5,1),c(0,0,0.5,1),c(1,1,0.5,1),11) xxcol-color.gradient(c(1,1,0.5,1),c(0.5,0.5,0.5,1),c(0.5,0.5,0.5,1),11) #xylab-dados$maslab #xxlab-dados$femlab #agelabels-xylab par(mar=pyramid.plot(xy.pop, xx.pop, labels= rep(,length(xy.pop)), top.labels=c(Masculino, , Feminino), main=Primeiras 10 cancros mais frequentes por sexo..., xycol=xycol,xxcol=xxcol, gap=0)) text(-xy.pop-5*nchar(dados$maslab), 1:length(xy.pop), dados$maslab );text(xx.pop+7*nchar(dados$femlab), 1:length(xx.pop), dados$femlab ) # Could not get the right ratio of xx.pop to nchar to get completely correct placement and given the small number you might just want to put in a hand-crafted vector, # The problem is (1) I do not want plot agelabels on the center and (2) I want plot different labels for each pair of the bars (one label for masculine and the other feminine). The data represent the 10 most frequent cancer in a group of individuals. Can some one help please? Caveman -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz)