### This script prepares the chart of geographical latitude vs. human development, a.k.a. why the 'Global South'' is a terrible term ### Author: Dimiter Toshkov, http://www.dimiter.eu, last edited: 6 November 2018 # Libraries and functions ------------------------------------------------- library(extrafont) #to use custom fonts library(sysfonts) #to load custom fonts library(jsonlite) #needed by sysfonts library(RCurl) library(showtext) #to use the custom fonts library(maps) #for the latitude data library(diagram) #for arrows library(car) #for recoding library(wbstats) #for downloading WB data library(scales) #for rescaling variables library(animation) # for gifs #fonts font_add_google('Cairo') #get the fonts font_add_google("Montserrat") font.families() #check that the fonts are installed and available # Get data ---------------------------------------------------------------- setwd('F:/BLOGS materials/Global South') #set workind directory capitals<-world.cities[world.cities$capital==1,c('country.etc','lat')] #latitude of capitals colnames(capitals)<-c('country','lat') capitals[nrow(capitals) + 1,] = list("Hong Kong",22.39) capitals[nrow(capitals) + 1,] = list("Montenegro",42.43) capitals[nrow(capitals) + 1,] = list("Fiji",17.71) capitals[nrow(capitals) + 1,] = list("Palestine",31.30) capitals[nrow(capitals) + 1,] = list("South Sudan",4.85) #HDI data from here: http://hdr.undp.org/en/data (some country names are changed manually to match the other dataset) hdi<-read.table("hdi_ts.txt", sep='\t', head=T) hdi$country<-trimws(hdi$country) #remove white space hdi$country<-recode(hdi$country, "'Brunei Darussalam'='Brunei';'Cabo Verde'='Cape Verde'; 'Korea'='Korea South';'Serbia'='Serbia and Montenegro'; 'Russian Federation'='Russia';'Syrian Arab Republic'='Syria';'Eswatini'='Swaziland'; 'United Kingdom'='UK';'US'='USA'; 'Czechia'='Czech Republic'; 'Saint Vincent and the Grenadines'='Saint Vincent and The Grenadines'; 'Viet Nam'='Vietnam';'Timor-Leste'='East Timor';'DR Congo'='Congo Democratic Republic'") setdiff(capitals$country, hdi$country) setdiff(hdi$country, capitals$country) data<-merge(hdi, capitals, by='country') #merge with the latitude data colnames(data)[2:9]<-c('hdi.1990', 'hdi.2000', 'hdi.2010', 'hdi.2012', 'hdi.2014', 'hdi.2015', 'hdi.2016', 'hdi.2017') data$country[data$country=='Serbia and Montenegro']='Serbia' #population data pop_data <- wb(indicator = "SP.POP.TOTL", startdate = 2017, enddate = 2017) pop<-pop_data[47:262,c("country","value")] pop$country<-gsub(",","", pop$country) pop[nrow(pop) + 1,] = list("Eritrea",5187948) pop$country<-recode(pop$country, "'Brunei Darussalam'='Brunei';'Cabo Verde'='Cape Verde';'Kyrgyz Republic'='Kyrgyzstan';'Timor-Leste'='East Timor'; 'Russian Federation'='Russia';'St. Kitts and Nevis'='Saint Kitts and Nevis' ;'Bahamas The'='Bahamas'; 'Congo Dem. Rep.'='Congo Democratic Republic'; 'Congo Rep.'='Congo'; 'Egypt Arab Rep.'='Egypt';'Gambia The'='Gambia'; 'Iran Islamic Rep.'='Iran';'Korea Rep.'='Korea South'; 'Lao PDR'='Laos'; 'Macedonia FYR'='Macedonia';'Micronesia Fed. Sts.'='Micronesia'; 'St. Lucia'='Saint Lucia';'St. Vincent and the Grenadines'='Saint Vincent and The Grenadines'; 'Slovak Republic'='Slovakia';'Eswatini'='Swaziland';'Syrian Arab Republic'='Syria'; 'Venezuela RB'='Venezuela';'United Kingdom'='UK';'United States'='USA';'Yemen Rep.'='Yemen'; 'Hong Kong SAR China'='Hong Kong'; 'West Bank and Gaza'='Palestine'") pop$country[pop$country=="Cote d'Ivoire"]<-'Ivory Coast' setdiff(pop$country, data$country) setdiff(data$country, pop$country) data<-merge(data, pop, by='country') colnames(data)[11]<-'pop' data$pop.r<-rescale(data$pop, to = c(0.5, 5)) #other variables landlocked<-c(' Afghanistan ' , ' Andorra ' ,' Armenia ' ,' Artsakh ' ,' Austria ' , ' Azerbaijan ' ,' Belarus ' , ' Bhutan ' ,' Bolivia ' ,' Botswana ' ,' Burkina Faso ' , ' Burundi ' , ' Central African Republic ' , ' Chad ' ,' Czech Republic ' ,' Ethiopia ' ,' Hungary ' ,' Kazakhstan ' ,' Kyrgyzstan ' ,' Laos ' , ' Lesotho ' , ' Liechtenstein ' , ' Luxembourg ' ,' Macedonia ' ,' Malawi ' ,' Mali ' ,' Moldova ' , ' Mongolia ' , ' Nepal ' , ' Niger ' ,' Paraguay ' , ' Rwanda ' , ' Serbia ' , ' Slovakia ' , ' South Sudan ' ,' Swaziland ' , ' Switzerland ' , ' Tajikistan ' , ' Turkmenistan ' , ' Uganda ' ,' Uzbekistan ' ,' Zambia ' ,' Zimbabwe ') landlocked<-trimws(landlocked) islands<-c(' Antigua and Barbuda ' ,' Bahamas ' , ' Bahrain ' , ' Barbados ' , ' Brunei ' , ' Cape Verde ' , ' Comoros ' , ' Cuba ' , ' Cyprus ' , ' Dominica ' , ' Dominican Republic ' , ' East Timor ' , ' Micronesia ' ,' Fiji ' , ' Grenada ' , ' Haiti ' , 'Hong Kong', ' Iceland ' ,' Indonesia ' , ' Ireland ' ,' Jamaica ' , ' Japan ' , ' Kiribati ' , ' Madagascar ' , ' Maldives ' , ' Malta ' , ' Marshall Islands ' , ' Mauritius ' , ' Nauru ' ,' New Zealand ' , ' Northern Cyprus ' , ' Palau ' ,' Papua New Guinea ' , ' Philippines ' , ' Saint Kitts and Nevis ' , ' Saint Lucia ' ,' Saint Vincent and The Grenadines ' ,' Samoa ' , ' Sao Tome and Principe ' , ' Seychelles ' ,' Singapore ' ,' Solomon Islands ' , ' Sri Lanka ' , ' Taiwan ' ,' Tonga ' ,' Trinidad and Tobago ' ,' Tuvalu ' , ' UK ' ,' Vanuatu ') islands<-trimws(islands) ussr<-c('Estonia','Latvia','Lithuania','Russia','Ukraine','Moldova','Armenia','Georgia','Azerbaijan', 'Kazakhstan','Kyrgyzstan','Tajikistan','Turkmenistan','Uzbekistan') eu<-c('Estonia','Latvia','Lithuania','Poland','Hungary','Slovakia','Czech Republic','Slovenia','Croatia', 'Bulgaria','Romania','Cyprus','Malta', 'Finland','Denmark','Sweden','Netherlands','Belgium','Luxembourg','Ireland','UK','Germany','Austria','France','Italy','Greece','Spain','Portugal') eu00<-c('Finland','Denmark','Sweden','Netherlands','Belgium','Luxembourg','Ireland','UK','Germany','Austria','France','Italy','Greece','Spain','Portugal') comunist<-c('Mongolia','Serbia','Montenegro', 'Croatia','Slovenia','Macedonia','Bosnia and Herzegovina','Bulgaria','Albania','Poland', 'Romania','Czech Republic','Slovakia','Hungary', 'Yemen','Somalia','Ethiopia','Mozambique','Benin','Angola','Madagascar','Afghanistan','Grenada', 'Cambodia','Mauritania','Gambia','Burkina Faso','Haiti', 'Congo Democratic Republic', 'China','Vietnam','China','Laos') setdiff(landlocked, data$country) setdiff(islands, data$country) setdiff(ussr, data$country) setdiff(eu, data$country) setdiff(comunist, data$country) data$landlocked<-data$country %in% landlocked data$island<-data$country %in% islands data$ussr<-data$country %in% ussr data$eu<-data$country %in% eu data$com<-data$country %in% comunist data$com2<-ifelse(data$com==T | data$ussr==T, 1, 0) data$eu00<-data$country %in% eu00 #subset data.s<-subset(data, data$country %in% c('Singapore','New Zealand', 'Australia', 'Niger', 'Iceland', 'Afghanistan', 'Brunei', 'Mozambique', 'Nepal', 'Tajikistan', 'Malawi', 'Burundi', 'Indonesia', 'Israel', 'Estonia', 'Kuwait', 'Morocco', 'Namibia', 'Portugal', 'USA', 'Central African Republic', 'Kyrgyzstan', 'Moldova', 'Ukraine', 'Seychelles', 'Lesotho', 'Swaziland', 'Bangladesh', 'Russia', 'Cuba')) # Figures: common settings -------------------------------------------------------------- showtext_auto() #this is to turn on the custom fonts availability showtext_opts(dpi = 92) #set the resolution: 96 is default #set colors background.color=rgb(255, 246, 229, max=255) #color for the background dark.color=rgb(45, 45, 68, max=255) # dark color main.color=rgb(255, 0, 51, alpha=205, max=255) #main color color1=rgb(39, 150, 131, alpha=205, max=255) color2=rgb(140, 73, 2, alpha=205, max=255) color3=rgb(0, 51, 153, alpha=205, max=255) color4=rgb(226, 4, 4, alpha=205, max=255) color5=rgb(226, 4, 4, alpha=205, max=255) data$custom.colors<-ifelse(data$island==T, color1, (ifelse(data$landlocked==T, color2, color5))) data$custom.shape<-ifelse(data$eu==T & data$com2==1, 23, (ifelse(data$eu==T, 24, (ifelse(data$com2==1, 25, 21))))) # Figure 1. HDI 2017 per latitude -------------------------------------------------------------- #set the main parameters: one plot, internal margins, outer margins, bacground color, no box, font pdf("f1_hdi_lat.pdf",width=13.2,height=9) png("f1_hdi_lat.png",width=1200, height=820, res=92) par(mfrow=c(1,1), mar=c(6,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(-45,68), ylim=c(0.34,1.01)) #start with an empty plot abline(v=c(-40,-23.26,0, 23.26, 40, 60), col='grey80') #add the vertical grid abline(h=seq(0.4,1,by=0.2), col='grey80') #add the horizontal grid labels=NA labels[1]<-expression(paste("-40" ,degree)) labels[2]<-expression(paste("-23", degree)) labels[3]<-expression(paste("0", degree)) labels[4]<-expression(paste("23", degree)) labels[5]<-expression(paste("40",degree)) labels[6]<-expression(paste("60",degree)) labels1=NA labels1[1]<-NA labels1[2]<-expression(italic("Tropic of Capricorn")) labels1[3]<-expression(italic("Equator")) labels1[4]<-expression(italic("Tropic of Cancer")) labels1[5]<-NA labels1[6]<-NA #horizontal axis axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(-40,-23.26,0, 23.26, 40, 60),line=0, labels=labels) axis (1, font=1, tck=-0.00, lwd=0, col=background.color, col.axis=dark.color, at=c(-40,-23.26,0, 23.26, 40, 60),line=1.5, labels=labels1) mtext(side=1,text=expression(paste("Latitude of the country's capital [", degree, "]")),line=5, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Human Development Index" * phantom(" (2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Human Development Index") * " (2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression line abline(lm(data$hdi.2017~data$lat), col=dark.color, lty=2.5, lwd=3) #loess line p<-predict(loess(data$hdi.2017~data$lat)) lines(x=data$lat[order(data$lat)], y=p[order(data$lat)], col=dark.color, lwd=2.5, lty=2) #arrow and label to regression line curvedarrow(from=c(-47, 0.455), to=c(-49, 0.475), lwd = 0.5, lty = 1, lcol = 'grey80', arr.col = 'grey80', arr.adj=0, arr.length=0.2, arr.width=0.05, arr.pos = 1, curve =-0.009, dr = 0.001) text('Linear regression line', x=-47.8, y=0.465, col=main.color, cex=1.0, adj=0, font=3) #(slope=0.003; R-squared=0.22) #arrow and label to loess line curvedarrow(from=c(-33, 0.67), to=c(-31, 0.722), lwd = 0.5, lty = 1, lcol = 'grey80', arr.col = 'grey80', arr.adj=0, arr.length=0.2, arr.width=0.05, arr.pos = 1, curve =0.003, dr = 0.001) text('Loess fit', x=-36, y=0.655, col=main.color, cex=1.0, adj=0, font=3) #text('Loess (non-parametric local regression) fit', x=-47.8, y=0.655, col=main.color, cex=0.8, adj=0, font=3) #arrow and label to loess line curvedarrow(from=c(-26.7, 0.94), to=c(-32.5, 0.94), lwd = 0.5, lty = 1, lcol = 'grey80', arr.col = 'grey80', arr.adj=0, arr.length=0.2, arr.width=0.08, arr.pos = 1, curve =0.000, dr = 0.001) text('each dot is a counry', x=-25, y=0.94, col=main.color, cex=1.0, adj=0, font=3) #title mtext(expression('The' * phantom (' "Global South" ') * 'and' * phantom(' "Global North" ') * 'are inaccurate, misleading terms: There is'), line=5, font=2, at=-54, col=dark.color, cex=1.8, adj=0, padj=1) mtext(expression(phantom('The') * ' "Global South" ' * phantom('and') * ' "Global North" ' * phantom('are inaccurate, misleading: There is')), line=5, font=3, at=-54, col=main.color, cex=1.8, adj=0, padj=1) mtext(expression('no ' * phantom('linear relationship between geographic latitude and human development.')), line=2.5, font=2, at=-54, col=main.color, cex=1.8, adj=0, padj=1) mtext(expression(phantom('no ') * 'linear relationship between geographic latitude and human development.'), line=2.5, font=2, at=-54, col=dark.color, cex=1.8, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=(data$lat), y=data$hdi.2017, pch=21, cex=2.5, col=dark.color, bg=main.color) #the country labels text(data$country, x=(data$lat), y=data$hdi.2017-0.02, cex=0.8, col=dark.color, font=3) #text(data.s$country, x=(data.s$lat), y=data.s$hdi.2017-0.031, cex=0.6, col=dark.color, font=3) #plot a selection only dev.off() # Figure 2, HDI 2017 per distance from equator ------------------------------------------------------------- #save to png #png("latitudeandhdi2.png", width=1024, height=512, res=92) #twitter size png("f2_hdi_eq.png", width=1200, height=820, res=92) #reddit size pdf("f2_hdi_eq.pdf", width=13.2, height=9) #set the main parameters: one plot, internal margins, outer margins, bacground color, no box, font par(mfrow=c(1,1), mar=c(6,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(-1.8,65), ylim=c(0.33,1.01)) #start with an empty plot abline(v=c(0, 23.26, 40, 60), col='grey80') #add the vertical grid abline(h=seq(0.4,1,by=0.2), col='grey80') #add the horizontal grid #horizontal axis labels=NA labels[1]<-expression(paste("0", degree)) labels[2]<-expression(paste("23", degree)) labels[3]<-expression(paste("40",degree)) labels[4]<-expression(paste("60",degree)) labels1=NA labels1[1]<-expression(italic("Equator")) labels1[2]<-expression(italic("Tropics")) labels1[3]<-NA labels1[4]<-NA axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=0, labels=labels) axis (1, font=1, tck=-0.00, lwd=0, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=1.5, labels=labels1) mtext(side=1,text=expression(paste("Distance from the equator of the country's capital [", degree, "]")),line=5, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Human Development Index" * phantom(" (2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Human Development Index") * " (2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression line abline(lm(data$hdi.2017~abs(data$lat)), col=dark.color, lty=3, lwd=3) #loess line p<-predict(loess(data$hdi.2017~abs(data$lat))) lines(x=abs(data$lat[order(abs(data$lat))]), y=p[order(abs(data$lat))], col=dark.color, lwd=3, lty=2) text('loess fit', x=0, y=0.655, col=main.color, cex=1.0, adj=0.5, font=3) text('linear fit', x=-2.4, y=0.53, col=main.color, cex=1.0, adj=0.5, font=3, srt=21) text('Correlation is 0.63', x=59, y=0.62, col=main.color, cex=1.0, adj=1, font=3) #title mtext('Human development and geographic position:', line=5, font=2, at=-7, col=dark.color, cex=2, adj=0, padj=1) mtext("distance from the equator is a strong predictor, but is not a verdict.", line=2.5, font=3, at=-7, col=dark.color, cex=1.8, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=abs(data$lat), y=data$hdi.2017, pch=21, cex=2.5, col=dark.color, bg=main.color) #the country labels text(data$country, x=abs(data$lat), y=data$hdi.2017-0.02, cex=0.8, col=dark.color, font=3) #text(data.s$country, x=abs(data.s$lat), y=data.s$hdi.2017-0.031, cex=0.6, col=dark.color, font=3) dev.off() # Figure 3. HDI2007, distance from equator, and country type ------------------------------------------------------ png("f3_hdi_eq.png", width=1200, height=820, res=92) #reddit size pdf("f3_hdi_eq.pdf", width=13.2, height=9) #set the main parameters: one plot, internal margins, outer margins, bacground color, no box, font par(mfrow=c(1,1), mar=c(6,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(-1.8,67), ylim=c(0.33,1.01)) #start with an empty plot abline(v=c(0, 23.26, 40, 60), col='grey80') #add the vertical grid abline(h=seq(0.4,1,by=0.2), col='grey80') #add the horizontal grid #horizontal axis labels=NA labels[1]<-expression(paste("0", degree)) labels[2]<-expression(paste("23", degree)) labels[3]<-expression(paste("40",degree)) labels[4]<-expression(paste("60",degree)) labels1=NA labels1[1]<-expression(italic("Equator")) labels1[2]<-expression(italic("Tropics")) labels1[3]<-NA labels1[4]<-NA axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=0, labels=labels) axis (1, font=1, tck=-0.00, lwd=0, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=1.5, labels=labels1) mtext(side=1,text=expression(paste("Distance from the equator of the country's capital [", degree, "]")),line=5, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Human Development Index" * phantom(" (2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Human Development Index") * " (2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression lines m1<-lm(data$hdi.2017~abs(data$lat)+abs(data$lat)*data$island+abs(data$lat)*data$landlocked) xt<-seq(0,65,1) yt1<-m1$coef[1]+m1$coef[2]*xt #no island, no landlocked yt2<-m1$coef[1]+m1$coef[2]*xt+m1$coef[3]+m1$coef[5]*xt #island yt3<-m1$coef[1]+m1$coef[2]*xt+m1$coef[4]+m1$coef[6]*xt #island lines(xt, yt1, col=color5, lty=1, lwd=3) lines(xt, yt2, col=color1, lty=1, lwd=3) lines(xt, yt3, col=color2, lty=1, lwd=3) rect(xleft=35.1, xright=69.9, ybottom=0.337, ytop=0.449, col=background.color, border=NA) test<-expression("Distance from the equator, indicators for" * phantom(" islands") * "," * phantom(" landlocked countries") * " ,") text(test, x=36, y=0.43, col=dark.color, cex=0.9, adj=0, font=2) test2<-expression(phantom("Distance from the equator, indicators for") * " islands" * phantom(",") * phantom(" landlocked countries") * " ,") text(test2, x=36, y=0.43, col=color1, cex=0.9, adj=0, font=2) test3<-expression(phantom("Distance from the equator, indicators for") * phantom(" islands") * phantom(",") * " landlocked countries" * " ,") text(test3, x=36, y=0.43, col=color2, cex=0.9, adj=0, font=2) test8<-expression('and their interactions account for' * phantom(" 55% ") * "of the variance in HDI (2017).") text (test8, x=36, y=0.405, col=dark.color, cex=0.9, adj=0, font=1) test9<-expression(phantom('and their interactions account for') * " 55% " * phantom("of the variance in HDI (2017).")) text (test9, x=36, y=0.405, col=color5, cex=0.9, adj=0, font=2) text ('Each line shows the best linear fit between HDI and distance from', x=36, y=0.38, col=dark.color, cex=0.9, adj=0, font=1) test4<-expression("the equator for" * phantom(" islands") * "," * phantom(" landlocked") * ", and" * phantom(" other ") * "countries.") text(test4, x=36, y=0.355, col=dark.color, cex=0.9, adj=0, font=2) test5<-expression(phantom ("the equator for") * " islands" * phantom(",") * phantom(" landlocked") * phantom(", and") * phantom(" other ") * phantom("countries.")) text(test5, x=36, y=0.355, col=color1, cex=0.9, adj=0, font=2) test6<-expression(phantom ("the equator for") * phantom(" islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") * phantom("countries.")) text(test6, x=36, y=0.355, col=color2, cex=0.9, adj=0, font=2) test7<-expression(phantom ("the equator for") * phantom(" islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " * phantom("countries.")) text(test7, x=36, y=0.355, col=color5, cex=0.9, adj=0, font=2) #title mtext('Geography and human development:', line=5, font=2, at=-7, col=dark.color, cex=2.2, adj=0, padj=1) mtext(expression(phantom("islands") * "," * phantom (" landlocked") * ", and" * phantom(" other ") * "countries, and distance from the equator."), line=2.5, font=3, at=-7, col=dark.color, cex=2.0, adj=0, padj=1) mtext(expression("islands" * phantom(",") * phantom (" landlocked") * phantom(", and") * phantom(" other ") *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color1, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color2, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color5, cex=2.0, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=abs(data$lat), y=data$hdi.2017, pch=21, cex=2.5, col=dark.color, bg=data$custom.colors) #the country labels text(data$country, x=abs(data$lat), y=data$hdi.2017-0.02, cex=0.8, col=dark.color, font=3) dev.off() #m2<-lm(data$hdi.2017~abs(data$lat)+abs(data$lat)*data$island+abs(data$lat)*data$landlocked+data$eu+data$com2) # Figure 4. HDI2007, distance from equator, and country type, different years --------------------------------------------------------- #search and replace the year to make the differnt plots png("hdilat2017.png", width=1200, height=820, res=92) #reddit size #set the main parameters: one plot, internal margins, outer margins, bacground color, no box, font par(mfrow=c(1,1), mar=c(6,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(-1.8,67), ylim=c(0.13,1.01)) #start with an empty plot abline(v=c(0, 23.26, 40, 60), col='grey80') #add the vertical grid abline(h=seq(0.2,1,by=0.2), col='grey80') #add the horizontal grid #horizontal axis labels=NA labels[1]<-expression(paste("0", degree)) labels[2]<-expression(paste("23", degree)) labels[3]<-expression(paste("40",degree)) labels[4]<-expression(paste("60",degree)) labels1=NA labels1[1]<-expression(italic("Equator")) labels1[2]<-expression(italic("Tropics")) labels1[3]<-NA labels1[4]<-NA axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=0, labels=labels) axis (1, font=1, tck=-0.00, lwd=0, col=background.color, col.axis=dark.color, at=c(0, 23.26, 40, 60),line=1.5, labels=labels1) mtext(side=1,text=expression(paste("Distance from the equator of the country's capital [", degree, "]")),line=5, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Human Development Index" * phantom(" (2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Human Development Index") * " (2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression lines m1<-lm(data$hdi.2017~abs(data$lat)+abs(data$lat)*data$island+abs(data$lat)*data$landlocked) xt<-seq(0,65,1) yt1<-m1$coef[1]+m1$coef[2]*xt #no island, no landlocked yt2<-m1$coef[1]+m1$coef[2]*xt+m1$coef[3]+m1$coef[5]*xt #island yt3<-m1$coef[1]+m1$coef[2]*xt+m1$coef[4]+m1$coef[6]*xt #island lines(xt, yt1, col=color5, lty=1, lwd=3) lines(xt, yt2, col=color1, lty=1, lwd=3) lines(xt, yt3, col=color2, lty=1, lwd=3) rect(xleft=34, xright=69.9, ybottom=0.23, ytop=0.38, col=background.color, border=NA) test<-expression("Distance from equator, indicators for " * phantom(" islands") * "," * phantom(" landlocked countries") * ",") text(test, x=35, y=0.35, col=dark.color, cex=0.9, adj=0, font=2) test2<-expression(phantom("Distance from equator, indicators for ") * " islands" * phantom(",") * phantom(" landlocked countries") * ",") text(test2, x=35, y=0.35, col=color1, cex=0.9, adj=0, font=2) test3<-expression(phantom("Distance from equator, indicators for ") * phantom(" islands") * phantom(",") * " landlocked countries" * ",") text(test3, x=35, y=0.35, col=color2, cex=0.9, adj=0, font=2) test8<-expression('and their interactions account for ' * phantom(" 55% ") * "of the variance in HDI (2017).") text (test8, x=35, y=0.32, col=dark.color, cex=0.9, adj=0, font=1) test9<-expression(phantom('and their interactions account for ') * " 55% " * phantom("of the variance in HDI (2017).")) text (test9, x=35, y=0.32, col=color5, cex=0.9, adj=0, font=2) text ("2017", x=60, y=0.5, col='grey80', cex=7, adj=.5, font=2) text ('Each line shows the best linear fit between HDI and distance from', x=35, y=0.29, col=dark.color, cex=0.9, adj=0, font=1) test4<-expression("equator for" * phantom(" islands") * "," * phantom(" landlocked") * ", and" * phantom(" other ") * "countries.") text(test4, x=35, y=0.26, col=dark.color, cex=0.9, adj=0, font=2) test5<-expression(phantom ("equator for") * " islands" * phantom(",") * phantom(" landlocked") * phantom(", and") * phantom(" other ") * phantom("countries.")) text(test5, x=35, y=0.26, col=color1, cex=0.9, adj=0, font=2) test6<-expression(phantom ("equator for") * phantom(" islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") * phantom("countries.")) text(test6, x=35, y=0.26, col=color2, cex=0.9, adj=0, font=2) test7<-expression(phantom ("equator for") * phantom(" islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " * phantom("countries.")) text(test7, x=35, y=0.26, col=color5, cex=0.9, adj=0, font=2) #title mtext('Geography and human development:', line=5, font=2, at=-7, col=dark.color, cex=2.2, adj=0, padj=1) mtext(expression(phantom("islands") * "," * phantom (" landlocked") * ", and" * phantom(" other ") * "countries, and distance from the equator."), line=2.5, font=3, at=-7, col=dark.color, cex=2.0, adj=0, padj=1) mtext(expression("islands" * phantom(",") * phantom (" landlocked") * phantom(", and") * phantom(" other ") *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color1, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color2, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " *phantom("countries, and distance from the equator.")), line=2.5, font=3, at=-7, col=color5, cex=2.0, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=abs(data$lat), y=data$hdi.2017, pch=21, cex=2.5, col=dark.color, bg=data$custom.colors) #the country labels text(data$country, x=abs(data$lat), y=data$hdi.2017-0.02, cex=0.8, col=dark.color, font=3) dev.off() # Make GIF ---------------------------------------------------------------- #make the animation im.convert('hdilat*.png', output = "testanimation.gif", convert = "convert") # HDI by population ------------------------------------------------------- #png("hdipop.png", width=1200, height=820, res=92) #reddit size pdf("hdipop.pdf", width=13.2, height=9) #reddit size #set the main parameters: one plot, internal margins, outer margins, bacground color, no box, font par(mfrow=c(1,1), mar=c(5,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(9.5,21.5), ylim=c(0.33,1.01)) #start with an empty plot abline(v=c(log(1e+4),log(1e+5),log(1e+6),log(1e+7),log(1e+8),log(1e+9)), col='grey80') #add the vertical grid abline(h=seq(0.4,1,by=0.2), col='grey80') #add the horizontal grid #horizontal axis axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(log(1e+4),log(1e+5),log(1e+6),log(1e+7),log(1e+8),log(1e+9)), labels=c('10 thousand', '100 thousand','1 million','10 million','100 million','1 billion')) mtext(side=1,text=expression("Population of a country" * phantom(" (log)")),line=4, font=1, col=dark.color, cex=1.5) mtext(side=1,text=expression(italic(phantom("Population of a country") * " (log)")),line=4, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Human Development Index" * phantom(" (2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Human Development Index") * " (2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression lines m3<-lm(data$hdi.2017~log(data$pop)) xt<-seq(9.6,21.2,0.1) yt1<-m3$coef[1]+m3$coef[2]*xt lines(xt, yt1, col=dark.color, lty=1, lwd=2) #loess p<-predict(loess(data$hdi.2017~log(data$pop), span=0.7)) lines(x=log(data$pop)[order(log(data$pop))], y=p[order(log(data$pop))], col=main.color, lwd=3, lty=1) #arrow and label to regression line text('Linear fit', x=log(12000), y=0.74, col=dark.color, cex=1.0, adj=0, font=3, srt=-2) #arrow and label to loess line text('Loess fit', x=log(16000), y=0.83, col=main.color, cex=1.0, adj=0, font=3) #title mtext('Population size and human development:', line=5, font=2, at=8.7, col=dark.color, cex=2.2, adj=0, padj=1) mtext(expression(phantom("islands") * "," * phantom (" landlocked") * ", and" * phantom(" other ") * "countries."), line=2.5, font=3, at=8.7, col=dark.color, cex=2.0, adj=0, padj=1) mtext(expression("islands" * phantom(",") * phantom (" landlocked") * phantom(", and") * phantom(" other ") *phantom("countries.")), line=2.5, font=3, at=8.7, col=color1, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") *phantom("countries.")), line=2.5, font=3, at=8.7, col=color2, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " *phantom("countries.")), line=2.5, font=3, at=8.7, col=color5, cex=2.0, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=log(data$pop), y=data$hdi.2017, pch=21, cex=2.5, col=dark.color, bg=data$custom.colors) #the country labels text(data$country, x=log(data$pop), y=data$hdi.2017-0.02, cex=0.8, col=dark.color, font=3) dev.off() # Change in HDI by population --------------------------------------------- #png("hdipopchange.png", width=1200, height=820, res=92) #reddit size pdf("hdipopchange.pdf", width=13.2, height=9) #reddit size par(mfrow=c(1,1), mar=c(5,5,1,1), oma=c(0,0,5,0), bg=background.color, bty='n', family='Montserrat') plot(NULL,type='n',axes=FALSE,ann=FALSE, xlim=c(9.1,21.5), ylim=c(-0.07,0.21)) #start with an empty plot abline(v=c(log(1e+4),log(1e+5),log(1e+6),log(1e+7),log(1e+8),log(1e+9)), col='grey80') #add the vertical grid abline(h=seq(-0.05,0.2,by=0.05), col='grey80') #add the horizontal grid #horizontal axis axis (1, font=1, tck=-0.01, col=background.color, col.axis=dark.color, at=c(log(1e+4),log(1e+5),log(1e+6),log(1e+7),log(1e+8),log(1e+9)), labels=c('10 thousand', '100 thousand','1 million','10 million','100 million','1 billion')) mtext(side=1,text=expression("Population of a country in 2017" * phantom(" (log)")),line=4, font=1, col=dark.color, cex=1.5) mtext(side=1,text=expression(italic(phantom("Population of a country in 2017") * " (log)")),line=4, font=1, col=dark.color, cex=1.5) #vertical axis axis (2, font=1, tck=-0.01, col=background.color, col.axis=dark.color) mtext(side=2,text=expression("Change in Human Development Index" * phantom(" (2000-2017)")),line=3, font=1, col=dark.color, cex=1.5) mtext(side=2,text=expression(italic(phantom("Change in Human Development Index") * " (2000-2017)")),line=3, font=3, col=dark.color, cex=1.5) #linear regression lines m3<-lm((data$hdi.2017-data$hdi.2000)~log(data$pop)) xt<-seq(9.6,21.2,0.1) yt1<-m3$coef[1]+m3$coef[2]*xt lines(xt, yt1, col=dark.color, lty=1, lwd=3) text('Linear fit', x=log(1000000000), y=0.105, col=dark.color, cex=1.0, adj=0.5, font=3, srt=6) #title mtext('Population size and change in human development:', line=5, font=2, at=8, col=dark.color, cex=2.2, adj=0, padj=1) mtext(expression(phantom("islands") * "," * phantom (" landlocked") * ", and" * phantom(" other ") * "countries."), line=2.5, font=3, at=8, col=dark.color, cex=2.0, adj=0, padj=1) mtext(expression("islands" * phantom(",") * phantom (" landlocked") * phantom(", and") * phantom(" other ") *phantom("countries.")), line=2.5, font=3, at=8, col=color1, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * " landlocked" * phantom(", and") * phantom(" other ") *phantom("countries.")), line=2.5, font=3, at=8, col=color2, cex=2.0, adj=0, padj=1) mtext(expression(phantom("islands") * phantom(",") * phantom(" landlocked") * phantom(", and") * " other " *phantom("countries.")), line=2.5, font=3, at=8, col=color5, cex=2.0, adj=0, padj=1) #signature mtext(text=expression("- dimiter " * phantom(".eu") * " -"), side=1, line=-1, outer=F, font=1, family='Cairo', col=dark.color, cex=1.0, adj=1, padj=1) mtext(text=expression(phantom("- dimiter ") * ".eu" * phantom(" -")), side=1, line=-1, outer=F, font=1, family='Cairo', col=main.color, cex=1.0, adj=1, padj=1) #the data! points(x=log(data$pop), y=(data$hdi.2017-data$hdi.2000), pch=21, cex=2.5, col=dark.color, bg=data$custom.colors) #the country labels text(data$country, x=log(data$pop), y=(data$hdi.2017-data$hdi.2000)-0.008, cex=0.8, col=dark.color, font=3) dev.off() ###THE END