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 ##################################### 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: orvaquim at cenfoss.co.mz cell: +258828810980
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.65975697In 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: orvaquim at cenfoss.co.mz > cell: +258828810980 > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
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("#8888ff",10),xxcol=rep("#ff88ff",10), gap=25)) -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pyramid.plot.R URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100214/d14e9434/attachment.pl>
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 <jim at 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("#8888ff",10),xxcol=rep("#ff88ff",10), gap=25)) >-- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaquim at cenfoss.co.mz cell: +258828810980
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 <jim at 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("#8888ff",10),xxcol=rep("#ff88ff",10), gap=25)) >-- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaquim at cenfoss.co.mz cell: +258828810980