
We can see that the childlessness data are a bit messy, especially when it comes to the first couple of rows and column names. # 2 Country ISO … Peri… Refe… Perc… Perc… As these rows contain the particular letter in all columns, we can delete these by deleting all rows for which all columns have equal values. Also, as you can see from the HTML table in the link, there are some rows that show the letter of the alphabet before starting with a list of countries of which the name starts with that letter. The first element in the resulting list contains our table of interest, and as the first column is empty, we delete it. One can obtain the XPath by hovering over the HTML table in developer mode in the browser, and having it show the XPath. We use the pipe (%>%) from the magrittr package to feed our URL of interest into functions that read the HTML table using the XPath and convert that to a data frame in R. We use the rvest package using the XPath to indicate what part of the web page contains our table of interest.

Therefore, we first scrape an HTML table of country names, ISO3, ISO2 and UN codes for all countries worldwide. As different data sets have different formats for country names (e.g., “United Kingdom of Great Britain and Northern Ireland” versus “United Kingdom”), we’ll match country names to ISO3 codes to easily merge all data sets later on. As we’ll make world maps, we need a way to map our data sets to geographical data containing coordinates (longitude and latitude). Now, we can continue with loading our data. Importing, exploring and cleaning the data Let’s first load the required packages into RStudio. We’ll start by loading and cleaning the data, whereafter we will build our interactive world maps in R Shiny. The data sources here are about childlessness and gender inequality, which is the focus of my PhD research, in which I computationally analyse the effects of gender and parental status on socio-economic inequalities. To show you how to adapt the interface of the app to the choices of the users, we’ll make use of two data sources such that the user can choose what data they want to explore, and that the app adapts the possible input choices to the users’ previous choices.

As the Shiny app cannot be embedded into this blog, I will direct you to the live app and show you in this post on my GitHub how to embed a Shiny app in your R Markdown files, which is a really cool and innovative way of preparing interactive documents.

In this post, I will show you how to create interactive world maps and how to show these in the form of an R Shiny app. She applies her interdisciplinary knowledge to computationally address societal problems of inequality.

With a passion for data science and a background in mathematics and econometrics. Florianne Verkroost is a PhD candidate at Nuffield College at the University of Oxford.
