1. Custom population pyramids The US census keeps demographic data estimates for every country in the world by year at: https://www.census.gov/data-tools/demo/idb/informationGateway.php

For this problem:

a)Download at least three pyramid data sets whose comparison is interesting. This could either be different countries in the same time, or different times in the same country. Be sure that the pyramids differ substantially in at least two you select. Describe in words why you chose the three sets, and what you hope to learn by looking at them.

b)Identify a color palette or color scheme from one of the libraries or functions we discussed in class (colorRamp, RColorBrewer, gplots, etc). Use a common color palette on each pyramid graph. You may use different colors for men and women.

c)Make the graphic that appears in your solution as professional as possible. There should be no strange axis labels. It should be a readable size, with appropriate titles.

d)Set the following arguments: lx, rx, rxcol,lxcol,labels,gap, space,show.values,labelcex,xlim, and main, and laxlabel/raxlabel if needed

e)Note that xlim takes two positive values, like c(25,25) .


Answer 1:

The data sets used are 3 data sets for the same country in different years which are: USA in 2005, USA in 2010 and USA in 2015.

I have chosen the 3 data sets for the same country to compare the population percentage changes in different years. As the 2 data sets have 10 years of difference, the population percentage would have a difference.

I am hoping that the percentages would have increased or decreased for male and female.

Example:

library(plotrix)
#Installing plotrix package and reading it. 

library(RColorBrewer)
#Installing RColorBrewer package and reading it. 

US1990<-read.csv(file = "D:/MTU Course Files/SEM 1/ASAD/Problem Set 4/Table4.csv", header = TRUE, sep = ",")
#Reading the downloaded CSV file

seacolors <- colors()[substr(colors(),1 ,3)== "sea"]
#Describing sea colors

agenames <- c("00 - 04","05-09","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80-84","85-89","90-94","95-99","100+")
#Describing Names as Excel is not showing properly. 

pyramid.plot(US1990$Percent.Male,US1990$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 1995 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",rxcol="turquoise1",lxcol=palette(seacolors[order(runif(2))]), labelcex = 0.7)

## [1] 5.1 4.1 4.1 2.1
#Usiing Palaette colors for LXCOL and using defined color for RXCOL. 

Code:

library(plotrix)
#Installing plotrix package and reading it. 

library(RColorBrewer)
#Installing RColorBrewer package and reading it. 

US2005<-read.csv(file = "D:/MTU Course Files/SEM 1/ASAD/Problem Set 4/Table1.csv", header = TRUE, sep = ",")
#Reading the downloaded CSV file

seacolors <- colors()[substr(colors(),1 ,3)== "sea"]
#Describing sea colors

agenames <- c("00 - 04","05-09","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80-84","85-89","90-94","95-99","100+")
#Describing Names as Excel is not showing properly. 

pyramid.plot(US2005$Percent.Male,US2005$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2005 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",lxcol=topo.colors(3),rxcol=cm.colors(3), labelcex = 0.7)

## [1] 5.1 4.1 4.1 2.1
#Using In-built color schemes for Pyramid plot. 

pyramid.plot(US2005$Percent.Male,US2005$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2005 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",rxcol="turquoise1",lxcol=palette(seacolors[order(runif(2))]), labelcex = 0.7)

## [1] 4 2 4 2
#Usiing Palaette colors for LXCOL and using defined color for RXCOL. 
library(plotrix)
#Installing plotrix package and reading it. 

library(RColorBrewer)
#Installing RColorBrewer package and reading it. 

US2010<-read.csv(file = "D:/MTU Course Files/SEM 1/ASAD/Problem Set 4/Table2.csv", header = TRUE, sep = ",")
#Reading the downloaded CSV file

seacolors <- colors()[substr(colors(),1 ,3)== "sea"]
#Describing sea colors

agenames <- c("00 - 04","05-09","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80-84","85-89","90-94","95-99","100+")
#Describing Names as Excel is not showing properly. 

pyramid.plot(US2010$Percent.Male,US2010$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2010 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",lxcol=topo.colors(3),rxcol=cm.colors(3), labelcex = 0.7)

## [1] 5.1 4.1 4.1 2.1
#Using In-built color schemes for Pyramid plot. 

pyramid.plot(US2010$Percent.Male,US2010$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2010 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",rxcol="turquoise1",lxcol=palette(seacolors[order(runif(2))]), labelcex = 0.7)

## [1] 4 2 4 2
#Usiing Palaette colors for LXCOL and using defined color for RXCOL. 
library(plotrix)
#Installing plotrix package and reading it. 

library(RColorBrewer)
#Installing RColorBrewer package and reading it. 

US2015<-read.csv(file = "D:/MTU Course Files/SEM 1/ASAD/Problem Set 4/Table3.csv", header = TRUE, sep = ",")
#Reading the downloaded CSV file

seacolors <- colors()[substr(colors(),1 ,3)== "sea"]
#Describing sea colors

agenames <- c("00 - 04","05-09","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80-84","85-89","90-94","95-99","100+")
#Describing Names as Excel is not showing properly. 

pyramid.plot(US2015$Percent.Male,US2015$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2015 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",lxcol=topo.colors(3),rxcol=cm.colors(3), labelcex = 0.7)

## [1] 5.1 4.1 4.1 2.1
#Using In-built color schemes for Pyramid plot. 

pyramid.plot(US2015$Percent.Male,US2015$Percent.Female,top.labels=c("Male ","Age","Female"),main = "Population Percentage of USA in the year 2015 ",laxlab =c (0:4 *2.5) , raxlab =c (0:4 *2.5), gap = 1.25, xlim = c(10,10), labels = agenames, unit = "Percentage of Population",rxcol="turquoise1",lxcol=palette(seacolors[order(runif(2))]), labelcex = 0.7)

## [1] 4 2 4 2
#Usiing Palaette colors for LXCOL and using defined color for RXCOL.