Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP)
2019-Sep-17 22:14 UTC
[R] bi-directional bar chart with a central axis
Hi R-help, I have this data: my.dta <-data.frame(matrix(c( 26.3, 21.4, 20.1, 13.4, 7.9, 3.9, 16.5, 14.6, 5.3, 3.6, 38.6, 25.6, 34.4, 21.6, 77.4, 79.5, 58.2, 56.1, 80.5, 84, 37.7, 31.9, 19.9, 28.1, 6.2, 5.9 ), nrow=13, ncol=2, byrow=T, dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), c("Males", "Females")) )) I want to make a graph that looks like this: https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/backtoback11.jpg?resize=864%2C379&ssl=1 Any help would be highly appreciated! Best, Jen
On 9/17/19 3:14 PM, Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help wrote:> Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/backtoback11.jpg?resize=864%2C379&ssl=1I suppose it helps to know that these are called "pyramid charts" because of their common use in demographic circles for displaying comparative population structures of men and women ("population pyramids"). https://markmail.org/search/?q=list%3Aorg.r-project.r-help+pyramid+chart Also look in the plotrix package since I seem to remember that it has one nicely documented and illustrated. -- David.> > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP)
2019-Sep-17 22:36 UTC
[R] bi-directional bar chart with a central axis
Oh, I guess I just wasn't thinking of them as population pyramids since the variables A-M are actually responses to unrelated survey questions and not age bins. But that's silo'd thinking because why would that matter? Thanks for the brain nudge. I'll check out the plotrix link. Jen -----Original Message----- From: David Winsemius <dwinsemius at comcast.net> Sent: Tuesday, September 17, 2019 6:32 PM To: Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) <fvv9 at cdc.gov>; r-help at r-project.org Subject: Re: [R] bi-directional bar chart with a central axis On 9/17/19 3:14 PM, Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help wrote:> Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/ba > cktoback11.jpg?resize=864%2C379&ssl=1I suppose it helps to know that these are called "pyramid charts" because of their common use in demographic circles for displaying comparative population structures of men and women ("population pyramids"). https://markmail.org/search/?q=list%3Aorg.r-project.r-help+pyramid+chart Also look in the plotrix package since I seem to remember that it has one nicely documented and illustrated. -- David.> > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 Jennifer, This is one way: library(plotrix) pyramid.plot(my.dta[,1],my.dta[,2], labels=c("Statement 1","Statement 2","Statement 3", "Statement 4","Statement 5","Statement 6", "Statement 7","Statement 8","Statement 9", "Statement 10","Statement 11","Statement 12","Statement 13"), top.labels=c("Males","Statement","Females"), main="My pyramid plot",unit="percent",gap=25) If you want to really get into pyramid plots, see the "pyramid" package. Jim On Wed, Sep 18, 2019 at 8:23 AM Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help <r-help at r-project.org> wrote:> > Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/backtoback11.jpg?resize=864%2C379&ssl=1 > > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP)
2019-Sep-17 22:51 UTC
[R] bi-directional bar chart with a central axis
Thanks, Jim (author of plotrix!), that's a real easy way to do it! I'll play around with options. Jen -----Original Message----- From: Jim Lemon <drjimlemon at gmail.com> Sent: Tuesday, September 17, 2019 6:43 PM To: Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) <fvv9 at cdc.gov>; r-help mailing list <r-help at r-project.org> Subject: Re: [R] bi-directional bar chart with a central axis Hi Jennifer, This is one way: library(plotrix) pyramid.plot(my.dta[,1],my.dta[,2], labels=c("Statement 1","Statement 2","Statement 3", "Statement 4","Statement 5","Statement 6", "Statement 7","Statement 8","Statement 9", "Statement 10","Statement 11","Statement 12","Statement 13"), top.labels=c("Males","Statement","Females"), main="My pyramid plot",unit="percent",gap=25) If you want to really get into pyramid plots, see the "pyramid" package. Jim On Wed, Sep 18, 2019 at 8:23 AM Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help <r-help at r-project.org> wrote:> > Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/ba > cktoback11.jpg?resize=864%2C379&ssl=1 > > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Richard M. Heiberger
2019-Sep-17 22:54 UTC
[R] bi-directional bar chart with a central axis
I would use the likert function in the HH package> library(HH) > likert(my.dta) > as.pyramidLikert(likert(my.dta)) >See the demo demo("likert-paper", package="HH", ask=FALSE) for more complex examples, including the population pyramid. We can also get the multiple coloring that your posted example shows. Rich On Tue, Sep 17, 2019 at 6:23 PM Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help <r-help at r-project.org> wrote:> > Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/backtoback11.jpg?resize=864%2C379&ssl=1 > > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP)
2019-Sep-17 23:02 UTC
[R] bi-directional bar chart with a central axis
Oh, that's a nice option, too. Thanks! -----Original Message----- From: Richard M. Heiberger <rmh at temple.edu> Sent: Tuesday, September 17, 2019 6:54 PM To: Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) <fvv9 at cdc.gov> Cc: r-help at r-project.org Subject: Re: [R] bi-directional bar chart with a central axis I would use the likert function in the HH package> library(HH) > likert(my.dta) > as.pyramidLikert(likert(my.dta)) >See the demo demo("likert-paper", package="HH", ask=FALSE) for more complex examples, including the population pyramid. We can also get the multiple coloring that your posted example shows. Rich On Tue, Sep 17, 2019 at 6:23 PM Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help <r-help at r-project.org> wrote:> > Hi R-help, > > I have this data: > > my.dta <-data.frame(matrix(c( > 26.3, 21.4, > 20.1, 13.4, > 7.9, 3.9, > 16.5, 14.6, > 5.3, 3.6, > 38.6, 25.6, > 34.4, 21.6, > 77.4, 79.5, > 58.2, 56.1, > 80.5, 84, > 37.7, 31.9, > 19.9, 28.1, > 6.2, 5.9 > ), nrow=13, ncol=2, byrow=T, > dimnames=list(c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'), > c("Males", "Females")) > )) > > I want to make a graph that looks like this: > > https://i1.wp.com/stephanieevergreen.com/wp-content/uploads/2012/11/ba > cktoback11.jpg?resize=864%2C379&ssl=1 > > Any help would be highly appreciated! > > Best, > > Jen > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.