Set up my data

library(ggplot2)
Task13 <- read.csv("~/Dropbox/UNDP_HDRO - Internship//Task13 - HALE/HALE.csv", header=T)
Task13$EYS.2013       <- as.numeric(as.character(Task13$EYS.2013))
## Warning: NAs introduced by coercion
Task13$EYS.2014       <- as.numeric(as.character(Task13$EYS.2014))
## Warning: NAs introduced by coercion
Task13$HALE           <- as.numeric(as.character(Task13$HALE))
Task13$HDI.2013       <- as.numeric(as.character(Task13$HDI.2013))
## Warning: NAs introduced by coercion
Task13$HDI.2014       <- as.numeric(as.character(Task13$HDI.2014))
## Warning: NAs introduced by coercion
Task13$Pop.2014       <- as.numeric(as.character(Task13$Pop.2014))
Task13$Pop.2013       <- as.numeric(as.character(Task13$Pop.2013))
Task13$Pop.5.24.2014  <- as.numeric(as.character(Task13$Pop.5.24.2014))
Task13$Pop.5.24.2013  <- as.numeric(as.character(Task13$Pop.5.24.2013))
## Warning: NAs introduced by coercion
Task13$Pop.adult.2014 <- as.numeric(as.character(Task13$Pop.adult.2014))
Task13$Pop.adult.2013 <- as.numeric(as.character(Task13$Pop.adult.2013))
Task13$GNI.2013[Task13$GNI.2013 > 75000] <- 75000
Task13$GNI.2014[Task13$GNI.2014 > 75000] <- 75000
Task13$EYS.2013[Task13$EYS.2013 > 18]    <- 18
Task13$EYS.2014[Task13$EYS.2014 > 18]    <- 18

Show scatterplot of Life Expectancy vs. Health Adjusted Life Expectancy

Reg.col.list <- c("#1b9e77","#d95f02","#7570b3", "#e7298a", "#66a61e", "#e6ab02", "#a6761d", "#666666")
palette(Reg.col.list)
plot(Task13$HALE~Task13$LE.2013,
     main="Health Quartiles in 2013",
     xlab="Life Expectancy 2013",
     ylab="Health-Adjusted Life Expectancy 2013",
     font.lab=2,
     col=Task13$Region,
     #xlim=c(45,85),
     #ylim=c(45,80),
     pch=16,
     cex=.5)
plot of chunk unnamed-chunk-2
legend(70, 48.5, legend = levels(HALE.diff$Region), col = 1:8, cex = .65, pch = 16)
## Error in levels(HALE.diff$Region): object 'HALE.diff' not found

Histogram of countries with large differences between LE and HALE

ggplot(aes(Task13$LE.2013 - Task13$HALE), data=Task13) +
  ggtitle("Life Expectancy (LE) vs. Health-Adjusted Life Expectancy (HALE):\n2013 Difference") +
  xlab ("Difference: 2013 LE - 2013 HALE") +
  ylab ("Frequency of Difference") +
  theme(plot.title=element_text(face="bold", size=12), axis.ticks=element_blank())+
  geom_bar(aes(fill=Region, labels=TRUE),col="black", binwidth=1) +
  scale_fill_manual(values = c("#1b9e77","#d95f02","#7570b3", "#e7298a","#66a61e", "#e6ab02", "#a6761d", "#666666"))+
  stat_bin(aes(label=..count.., fill=Region, y=..count..), vjust=1.5, geom="text", binwidth=1, colour="black",size=3.5,drop=TRUE) +
  geom_text(stat="bin", binwidth = 1, aes(label=..count..), size=3.75, vjust=-0.25, fontface="bold", drop=TRUE) +
  scale_y_continuous(breaks=seq(0,35,1)) +
  scale_x_continuous(breaks=seq(0,15,1)) +
  annotate("text", label="Angola", cex=3.5, x=-2, y=1.5, fontface="bold") +
  annotate("text", label="Cote\nd'Ivoire", cex=3.5, x=-2, y=.5, fontface="bold",lineheight=.6) +
  annotate("text", label="Sierra\nLeone", cex=3.5, x=.5, y=-.5, fontface="bold",lineheight=.6) +
  annotate("text", label="Turkmenistan", cex=3.5, x=1.75, y=3.5, fontface="bold") +
  annotate("text", label="Malawi", cex=3.5, x=13.5, y=24.5, fontface="bold") +
  annotate("text", label="Namibia", cex=3.5, x=13.6, y=23.75, fontface="bold") +
  annotate("text", label="Bangladesh", cex=3.5, x=14.25, y=22.5, fontface="bold") +
  annotate("text", label="Afghanistan", cex=3.5, x=14.25, y=21.75, fontface="bold") +
  annotate("text", label="Dominica", cex=3, x=12.75, y=-.5, fontface="bold") +
  annotate("text", label="Gabon", cex=3.5, x=14.25, y=10.5, fontface="bold") +
  annotate("text", label="Switzerland", cex=3.5, x=14.75, y=9.5, fontface="bold") +
  annotate("text", label="Australia", cex=3.5, x=14.5, y=8.75, fontface="bold") +
  annotate("text", label="Italy", cex=3.5, x=14, y=8, fontface="bold") +
  annotate("text", label="New Zealand", cex=3.5, x=15, y=7.25, fontface="bold") +
  annotate("text", label="Sweden", cex=3.5, x=14.5, y=6.5, fontface="bold") +
  annotate("text", label="Spain", cex=3.5, x=14.25, y=5.75, fontface="bold") +
  annotate("text", label="Netherlands", cex=3.5, x=15, y=5, fontface="bold") +
  annotate("text", label="Luxembourg", cex=3.5, x=15, y=4.25, fontface="bold") +
  annotate("text", label="Finland", cex=3.5, x=14.5, y=3.5, fontface="bold") +
  annotate("text", label="Vanuatu", cex=3.5, x=15.5, y=.5, fontface="bold") +
  annotate("text", label="Macedonia, Romania, Pakistan, ", cex=3.5, x=2, y=32, fontface="bold") +
  annotate("text", label="Botswana, Congo, Rwanda, Belize, ", cex=3.5, x=2, y=31.5, fontface="bold")+
  annotate("text", label="Syria, Malaysia, Bhutan, Palestine, ", cex=3.5, x=2, y=31, fontface="bold")+
  annotate("text", label="Venezuela, Paraguay, Cabo Verde, ", cex=3.5, x=2.5, y=30.5, fontface="bold")+
  annotate("text", label="Bahrain, Colombia, Algeria, ", cex=3.5, x=2, y=30, fontface="bold")+
  annotate("text", label="Dominican Republic, Papua New Guinea, ", cex=3.5, x=2.5, y=29.5, fontface="bold")+
  annotate("text", label="Bosnia & Herzegovina, Qatar,", cex=3.5, x=2, y=29, fontface="bold")+
  annotate("text", label="Brunei Darussalam, Guinea-Bissau, Hungary,", cex=3.5, x=3, y=28.5, fontface="bold")+
  annotate("text", label="Senegal, Micronesia, Kazakhstan, Mauritius,", cex=3.5, x=3, y=28, fontface="bold")+
  annotate("text", label="Belarus, Samoa, Bulgaria, Croatia", cex=3.5, x=3, y=27.5, fontface="bold")
## ymax not defined: adjusting position using y instead
plot of chunk unnamed-chunk-3

Show Country Quartiles of 2013 LE and HALE 20

#SCATTERPLOT LE 2013 vs. HALE 2013 CORRELATIONS, color by region with ISO3 labels
palette(Reg.col.list)
plot(Task13$HALE~Task13$LE.2013,
     main="Health Quartiles in 2013",
     xlab="Life Expectancy 2013",
     ylab="Health-Adjusted Life Expectancy 2013",
     font.lab=2,
     col=Task13$Region,
     #xlim=c(45,85),
     #ylim=c(45,80),
     pch=16,
     cex=.5)
legend(70, 48.5, legend = levels(HALE.diff$Region), col = 1:8, cex = .65, pch = 16)
## Error in levels(HALE.diff$Region): object 'HALE.diff' not found
#Create quartile for LOW HEALTH
segments(49.00, 42.10, 49.00, 56.88, col="#525252") #left
segments(49.00, 42.10, 64.88, 42.10, col="#525252") #bottom
segments(64.88, 42.10, 64.88, 56.88, col="#525252") #right
segments(49.00, 56.88, 64.88, 56.88, col="#525252") #top

#Create quartile for MED HDI
segments(64.88, 56.88, 64.88, 64.05, col="#525252") #left
segments(64.88, 56.88, 72.95, 56.88, col="#525252") #bottom
segments(72.95, 56.88, 72.95, 64.05,col="#525252") #right
segments(64.88, 64.05, 72.95, 64.05,col="#525252") #top

#Create quartile for HIGH HDI
segments(72.95, 64.05, 72.95, 67.38, col="#525252") #left
segments(72.95, 64.05, 76.60, 64.05 , col="#525252") #bottom
segments(76.60, 64.05, 76.60, 67.38, col="#525252") #right
segments(72.95, 67.38, 76.60, 67.38, col="#525252") #top

#Create quartile for VERY HIGH HDI
segments(76.60, 67.38, 76.60, 73.38, col="#525252") #left
segments(76.60, 67.38, 83.80, 67.38 , col="#525252") #bottom  
segments(83.80, 67.38, 83.80, 73.38, col="#525252") #right  
segments(76.60, 73.38, 83.80, 73.38, col="#525252") #top  

text(x = 56, y = 60, cex = .7, labels = "Low LE\n Medium HALE")
text(x = 66.5, y = 65.4, cex = .7, labels = "Medium LE\n High HALE")
text(x = 73.5, y = 72, cex = .7, labels = "High LE\n Very High HALE")
text(x = 68, y = 52, cex = .7, labels = "Medium LE\n Low HALE")
text(x = 76, y = 60, cex = .7, labels = "High LE\n Medium HALE")
text(x = 82, y = 65, cex = .65, labels = "Very High LE\n High HALE")
plot of chunk unnamed-chunk-4
ggplot(aes(Task13$LE.2013 - Task13$HALE), data=Task13) +
  ggtitle("Life Expectancy (LE) vs. Health-Adjusted Life Expectancy (HALE):\n2013 Difference") +
  xlab ("Difference: 2013 LE - 2013 HALE") +
  ylab ("Frequency of Difference") +
  theme(plot.title=element_text(face="bold", size=12), axis.ticks=element_blank())+
  geom_bar(aes(fill=Region, labels=TRUE),col="black", binwidth=1) +
  scale_fill_manual(values = c("#1b9e77","#d95f02","#7570b3", "#e7298a","#66a61e", "#e6ab02", "#a6761d", "#666666"))+
  stat_bin(aes(label=..count.., fill=Region, y=..count..), vjust=1.5, geom="text", binwidth=1, colour="black",size=3.5,drop=TRUE) +
  geom_text(stat="bin", binwidth = 1, aes(label=..count..), size=3.75, vjust=-0.25, fontface="bold", drop=TRUE) +
  scale_y_continuous(breaks=seq(0,35,1)) +
  scale_x_continuous(breaks=seq(0,15,1)) +
  annotate("text", label="Angola", cex=3.5, x=-2, y=1.5, fontface="bold") +
  annotate("text", label="Cote\nd'Ivoire", cex=3.5, x=-2, y=.5, fontface="bold",lineheight=.6) +
  annotate("text", label="Sierra\nLeone", cex=3.5, x=.5, y=-.5, fontface="bold",lineheight=.6) +
  annotate("text", label="Turkmenistan", cex=3.5, x=1.75, y=3.5, fontface="bold") +
  annotate("text", label="Malawi", cex=3.5, x=13.5, y=24.5, fontface="bold") +
  annotate("text", label="Namibia", cex=3.5, x=13.6, y=23.75, fontface="bold") +
  annotate("text", label="Bangladesh", cex=3.5, x=14.25, y=22.5, fontface="bold") +
  annotate("text", label="Afghanistan", cex=3.5, x=14.25, y=21.75, fontface="bold") +
  annotate("text", label="Dominica", cex=3, x=12.75, y=-.5, fontface="bold") +
  annotate("text", label="Gabon", cex=3.5, x=14.25, y=10.5, fontface="bold") +
  annotate("text", label="Switzerland", cex=3.5, x=14.75, y=9.5, fontface="bold") +
  annotate("text", label="Australia", cex=3.5, x=14.5, y=8.75, fontface="bold") +
  annotate("text", label="Italy", cex=3.5, x=14, y=8, fontface="bold") +
  annotate("text", label="New Zealand", cex=3.5, x=15, y=7.25, fontface="bold") +
  annotate("text", label="Sweden", cex=3.5, x=14.5, y=6.5, fontface="bold") +
  annotate("text", label="Spain", cex=3.5, x=14.25, y=5.75, fontface="bold") +
  annotate("text", label="Netherlands", cex=3.5, x=15, y=5, fontface="bold") +
  annotate("text", label="Luxembourg", cex=3.5, x=15, y=4.25, fontface="bold") +
  annotate("text", label="Finland", cex=3.5, x=14.5, y=3.5, fontface="bold") +
  annotate("text", label="Vanuatu", cex=3.5, x=15.5, y=.5, fontface="bold") +
  annotate("text", label="Macedonia, Romania, Pakistan, ", cex=3.5, x=2, y=32, fontface="bold") +
  annotate("text", label="Botswana, Congo, Rwanda, Belize, ", cex=3.5, x=2, y=31.5, fontface="bold")+
  annotate("text", label="Syria, Malaysia, Bhutan, Palestine, ", cex=3.5, x=2, y=31, fontface="bold")+
  annotate("text", label="Venezuela, Paraguay, Cabo Verde, ", cex=3.5, x=2.5, y=30.5, fontface="bold")+
  annotate("text", label="Bahrain, Colombia, Algeria, ", cex=3.5, x=2, y=30, fontface="bold")+
  annotate("text", label="Dominican Republic, Papua New Guinea, ", cex=3.5, x=2.5, y=29.5, fontface="bold")+
  annotate("text", label="Bosnia & Herzegovina, Qatar,", cex=3.5, x=2, y=29, fontface="bold")+
  annotate("text", label="Brunei Darussalam, Guinea-Bissau, Hungary,", cex=3.5, x=3, y=28.5, fontface="bold")+
  annotate("text", label="Senegal, Micronesia, Kazakhstan, Mauritius,", cex=3.5, x=3, y=28, fontface="bold")+
  annotate("text", label="Belarus, Samoa, Bulgaria, Croatia", cex=3.5, x=3, y=27.5, fontface="bold")
## ymax not defined: adjusting position using y instead
plot of chunk unnamed-chunk-5