Data examples using World Bank Data in combination with the ggplot package in R.
Tidyverse methods and functions were used to generate a combined data frame (tibble) for all countries and indicators.
1 |
countries.wb.data.map %>% filter( country == c("Afghanistan","Germany","Mexico") ) %>% ggplot( aes( x = `year` , y = `Population, total`, #size = `Population, total`, col = `country` #chape = `Region` ) ) + geom_point( ) + labs( title = "Population" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
countries.wb.data.map %>% filter( year > 2017 ) %>% filter( year < 2019 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = log( `GDP (constant 2010 US$)` ) , y = `Fertility rate, total (births per woman)`, size = `Population, total`, shape = `IncomeGroup`, col = `Region` #shape = as.character(`year`) ) ) + geom_point( ) + labs( title = "log( `GDP (constant 2010 US$)` ) vs. Fertility rate, total (births per woman)" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
countries.wb.data.map %>% filter( year > 2017 ) %>% filter( year < 2019 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = `GDP per capita (constant 2010 US$)`, y = `Fertility rate, total (births per woman)`, #size = `Population, total`, shape = `IncomeGroup`, col = `Region` #shape = as.character(`year`) ) ) + geom_point( ) + labs( title = "GDP per capita (constant 2010 US$) vs Fertility rate, total (births per woman)" ) + geom_label_repel( aes( label = ifelse( `IncomeGroup` == "Low income", country, "" ) ), hjust=0, #vjust=0.5, #nudge_y = 7, nudge_x = 150000, #force = 100, box.padding = 0.35, point.padding = 0.2, segment.color = "lightgray", direction = "y", # limits movement to x axis #color = "white", arrow = arrow( length = unit(0.03, "npc"), type = "closed", ends = "first" ) ) + #xlim( - 100, 60000000000000) + #scale_x_continuous( expand = expand_scale(mult = c( 0.4, 0.4 ))) + #scale_y_continuous( expand = expand_scale(mult = c( 0.1, 0.1))) + theme_bw() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
countries.wb.data.map %>% filter( year > 2017 ) %>% filter( year < 2019 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = `GDP per capita (constant 2010 US$)`, y = `Fertility rate, total (births per woman)`, #size = `Population, total`, #shape = `IncomeGroup`, col = `IncomeGroup` #shape = as.character(`year`) ) ) + geom_point( ) + geom_line() + geom_smooth() + theme_bw() + labs( title = "log( GDP per capita (constant 2010 US$) ) - Fertility rate, total (births per woman) " ) + xlim( 0, 50000 ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
countries.wb.data.map %>% filter( year > 2017 ) %>% filter( year < 2019 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)`, #size = `Population, total`, #shape = `IncomeGroup`, col = `IncomeGroup` #shape = as.character(`year`) ) ) + geom_point( ) + geom_line() + geom_smooth() + theme_bw() + labs( title = "log( GDP per capita (constant 2010 US$) ) - Fertility rate, total (births per woman) " ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
countries.wb.data.map %>% filter( year > 2017 ) %>% filter( year < 2019 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)` #size = `Population, total`, #shape = `IncomeGroup`, #col = `Region` #shape = as.character(`year`) ) ) + geom_line() + geom_smooth() + labs( title = "GDP per capita (constant 2010 US$) vs Fertility rate, total (births per woman) 2018" ) + geom_point( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)`, #size = `IncomeGroup`, shape = `IncomeGroup`, col = `Region` #shape = as.character(`year`) ) ) + geom_label_repel( aes( label = ifelse( `Fertility rate, total (births per woman)` > 5, `country`, "" ) ), hjust=0, #vjust=4, #nudge_y = 7, nudge_x = 11, #force = 100, #box.padding = 0.9, #point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) + geom_label_repel( aes( label = ifelse( `Fertility rate, total (births per woman)` < 1.25, `country`, "" ) ), #hjust=5, #vjust=2, #nudge_y = 0, nudge_x = -11, #force = 100, #box.padding = 0.9, point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
countries.wb.data.map %>% filter( year > 1980 ) %>% filter( year < 1982 ) %>% #filter( country == c("Austria","Germany","France") ) %>% ggplot( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)` #size = `Population, total`, #shape = `IncomeGroup`, #col = `Region` #shape = as.character(`year`) ) ) + geom_line() + geom_smooth() + labs( title = "GDP per capita (constant 2010 US$) vs Fertility rate, total (births per woman) 1981" ) + geom_point( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)`, #size = `IncomeGroup`, shape = `IncomeGroup`, col = `Region` #shape = as.character(`year`) ) ) + geom_label_repel( aes( label = ifelse( `Fertility rate, total (births per woman)` > 7.3, `country`, "" ) ), hjust=0, #vjust=4, #nudge_y = 7, nudge_x = 11, #force = 100, #box.padding = 0.9, #point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) + geom_label_repel( aes( label = ifelse( `Fertility rate, total (births per woman)` < 1.8, `country`, "" ) ), #hjust=5, #vjust=2, #nudge_y = 0, nudge_x = -11, #force = 100, #box.padding = 0.9, point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
countries.wb.data.map %>% filter( country == c("Austria","Germany", "France" ) ) %>% filter( year > 1960 ) %>% filter( year < 2019 ) %>% ggplot( aes( x = log( `GDP per capita (constant 2010 US$)` ), y = `Fertility rate, total (births per woman)`, #size = `Population, total`, #shape = `IncomeGroup`, col = `country` #shape = as.character(`year`) ) ) + geom_line( ) + geom_smooth() + geom_point( ) + geom_label_repel( aes( label = ifelse( `country` == "France", `year`, "" ) ), #hjust=3, #vjust=-4, nudge_y = 1, #nudge_x = 9, #force = 100, #box.padding = 0.9, #point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) + geom_label_repel( aes( label = ifelse( `country` == "Austria", `year`, "" ) ), #hjust=3, #vjust=-3, #nudge_y = 1, nudge_x = -3, #force = 100, #box.padding = 0.9, #point.padding = 0.2, segment.color = "lightgray", direction = "x" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) + geom_label_repel( aes( label = ifelse( `country` == "Germany", `year`, "" ) ), #hjust=3, #vjust=2, nudge_y = -4, #nudge_x = 9, #force = 100, #box.padding = 0.9, #point.padding = 0.2, segment.color = "lightgray", direction = "y" # limits movement to x axis #color = "white", #arrow = arrow( # length = unit(0.03, "npc"), # type = "closed", # ends = "first" ) ) + theme_bw() + labs( title = "log( `GDP per capita (constant 2010 US$)` ) - Fertility rate, total (births per woman) 1961 - 2018" ) |