

The goal here is to create variables that have different unique values for the different data, such that I can show you how to adapt the R Shiny app input to the users’ choices. The melt() function is included in package reshape2. Next, we melt the childlessness and gender gap index data into long format such that they will have similar shape and column names for merging.

The gender gap index data already contain these codes, so there’s no need for us to add these there. Now that the name changes for countries have been made, we can add the ISO3 codes to our childlessness and world map data.
Interactvie webmap code#
The code for doing so is long and tedious, so I won’t show that here, but for your reference you can find it here.
Interactvie webmap iso#
Unfortunately, to solve this, we need to manually change some country names in our data to match those in the ISO code data set. However, even between the ISO code data and the other data sets, there is discrepancy in country names. As I said before, these all have different notations for country names, which is why we’ll use the ISO3 codes. To map our data, we need to merge the childlessness, gender gap index, and world map data. Select(-Subindicator.Type, -Indicator.Id) csv file directly into RStudio from the URL link. Our second data set is about measures of gender inequality, provided by the World Bank. Note that when we convert the childlessness percentage columns to numeric type later on, the “.” values will automatically change to NA. We only want to maintain the columns that have country names, periods, and childlessness estimates for different age groups, as well as the rows that refer to data for specific countries. 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.
