I will be presenting sub-national fertility maps at session 110 “Projecting fertility in a time of demographic change: will it rise or will it fall?” this evening in meeting room 311 at 5pm.
I really like composite plots, where there’s a top part that describes a phenomenon and a bottom part with a synthetic time view of the overall process.
I’ve recently discovered this beautiful representation of educational differentials by gender, by Sara Lopus and Margaret Frye, and the beauty of this dataviz is that it tells a story on its own. (Click on the link for the publication)
I have used a random generated data to reproduce the graph in ggplot and used
gridExtra package to bind grobs, the top and bottom components.
grid.arrange(top, bottom, heights=c(10,5), widths=c(20), padding=0)
I have saved the map as a .png file png package and used
rasterGrob from package
grid to create a raster image graphical object.
Are rainbow palettes really that bad?
If it depended on me, my ideal color palettes would be the color of my favorite toy as a kid: fluo squishy slime, the kind that lights up in the dark. However, not everyone appreciates it, especially scientific journals.
In the end, the presence of colors should be motivated by what’s being represented: a cluster of lines depicting the TFR trends in every country in the world during the past century would not benefit from a 250 colors scale. However, it’s different for maps and heat-maps as the right palette can improve the message, condensing and directing information (see this Lancet paper ).
Rainbow palettes work however rather well (in my opinion) in some instances although they can easily be substituted with less catchy and more printer friendly colors.
I’ll always be a fan of bright colors but I see the point for plotting minimalism. I’ve really enjoyed this article: End of the Rainbow? New Map Scale is More Readable by People Who Are Color Blind
I have downloaded the json file from here and transformed it into a dataframe using the rjson package.
I have used a bunch of color palettes to compare results. Ever since, discovering the viridis palettes, I am a huge fan of the ‘magma’ and ‘inferno’ as their darkest color is a deep black and it’s easier to highlight everything else.
Cividis palette (from cividis library here):
Inverted grey palette:
Here’s the code for the cividis palette plot:
ggplot(dt, aes(order, year))+ geom_tile(aes(fill = temp)) + scale_fill_cividis(na.value = "transparent")+ scale_y_reverse(name='', breaks = c(1876, 1900, 1950, 2000, 2018), labels=c('1876', '1900', '1950', '2000', '2018'))+ scale_x_continuous(name='', breaks = c(30-15, 61-15, 92-15, 122-15), labels=c('June', 'July', 'August', 'September'))+ theme(axis.ticks.x = element_blank())+ geom_vline(xintercept=c(30, 61, 92), linetype = "longdash" )
Come meet me at EPC to discuss Spatial Demography!
Thursday, 7 June 2018, 9:00-10:30 Session 1 Motherhood, Labor Market and Wages: Contextual Determinants of Childbearing in Spain: A Spatial Panel Study
Friday, 8 June 2018, 11:00-12:30 Session 65 Fertility Trends and Prospects: The Geography of Fertility Rates in Low and Middle-Income Countries: Analysis of Cross-Sectional Surveys from 74 Countries
AKA how start getting around using grep, grepl, sub, gsub, regexp, gregexp.
Main difference between them is that while
grepl matches to
pattern within the character vector,
gregexpr return more detail.
gsub perform replacement on the basis of a regular expression.
This is my version of lazy labeling: run the same code changing just the input dataset
file <- "BEN_Benin_2013" #myfile
clabel <- substring(file, 1, 3) #country label is the iso3 code
cname <-sub( ".*_(.*)_.*", "\\1", file) #country name
year <- sub( ".*_(.*)_*", "\\1", file) #census year
More to follow on grep and grepl…
As PAA 2018 is approaching, I’m looking forward to talk more about spatial prediction and subnational fertility disaggregation using DHS household survey data and our research on fine grid scale mapping of demographic indicators in low income countries at WorldPop (University of Southampton) and Flowminder.
Come meet me at the session “Adolescent Transitions into Parenthood”, on Saturday 28th of April from 11:15am-12:45pm in Plaza Ballroom E (Sheraton Denver Downtown), I will present our paper “The geography of fertility rates in low and middle-income countries: analysis of cross-sectional surveys from 69 countries”.
Plot made in ggplot2 using geofacet, personal elaboration of Census data.
Here is the the geofacet gris, although maybe not one of the most exciting ones…
mygrid <- data.frame(
row = c(1, 1, 1, 2, 2, 3),
col = c(1, 2, 3, 2, 3, 3),
code = c("KWT1", "KWT2", "KWT3", "KWT4", "KWT5", "KWT6"),
name = c("Al-Jahra Governorate", "Capital (Al Asimah) Governorate", "Hawalli Governorate", "Al-Farwaniya Governorate", "Mubarak Al-Kabeer Governorate", "al Ahmadi Governorate"),
stringsAsFactors = FALSE