Lab 03 - Nobel laureates

In January 2017, Buzzfeed published an article on why Nobel laureates show immigration is so important for American science. You can read the article here. In the article they show that while most living Nobel laureates in the sciences are based in the US, many of them were born in other countries. This is one reason why scientific leaders say that immigration is vital for progress. In this lab we will work with the data from this article to recreate some of their visualizations as well as explore new questions.

Learning goals

Hello teams!

First things first: get to know your team members. You can find your team assignment here.

Your first task as a team is to come up with a team name. Then, the team lead for this week should submit this information here.

Workflow

This is the first week you’re working in teams. You have a team repository that each member of the team has access to. You can all push to this repository, but for this week only we will keep things simple and ask that the team lead for the week is the only one who pushes while others work on together with them.

Starting next week we’ll show you how you can all collectively work in a repo, the (mini) chaos that might result in (called a merge conflict), and how to resolve it.

Getting started

Go to the course GitHub organization and locate your Lab 03 repo, which should be named lab-03-nobel-winners-YOUR_TEAMNAME. Grab the URL of the repo, and clone it in RStudio. Refer to Lab 01 if you would like to see step-by-step instructions for cloning a repo into an RStudio project.

First, open the R Markdown document lab-03-nobel-winners.Rmd and Knit it. Make sure it compiles without errors. The output will be in the file markdown .md file with the same name.

Packages

We’ll use the tidyverse package for this analysis. Run the following code in the Console to load this package.

library(tidyverse)

Data

The dataset for this assignment can be found as a csv file in the data folder of your repository. You can read it in using the following.

nobel <- read_csv("data/nobel.csv")

The variable descriptions are as follows:

In a few cases the name of the city/country changed after laureate was given (e.g. in 1975 Bosnia and Herzegovina was called Austria-Hungary). In these cases the variables below reflect a different name than their counterparts without the suffix _original.

Exercises

Get to know your data

  1. How many observations and how many variables are in the dataset? Use inline code to answer this question.

There are some observations in this dataset that we will exclude from our analysis to match the Buzzfeed results.

  1. Create a new data frame called nobel_living that filters for

Confirm that once you have filtered for these characteristics you are left with a data frame with 228 observations.

✅ ⬆️ Commit and push your changes to GitHub with an appropriate commit message again. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards.

Most living Nobel laureates were based in the US when they won their prizes

… says the Buzzfeed article. Let’s see if that’s true.

First, we’ll create a new variable to identify whether the laureate was in the US when they won their prize. We’ll use the mutate() function for this. The following pipeline mutates the nobel_living data frame by adding a new variable called country_us. We use an if statement to create this variable. The first argument in the if_else() function we’re using to write this if statement is the condition we’re testing for. If country is equal to "USA", we set country_us to "USA". If not, we set the country_us to "Other".

Note that we can achieve the same result using the fct_other() function we’ve seen before (i.e. with country_us = fct_other(country, “USA”)). We decided to use the if_else() here to show you one example of an if statement in R.

Next, we will limit our analysis to only the following categories: Physics, Medicine, Chemistry, and Economics.

For the next exercise work with the nobel_living_science data frame you created above. This means you’ll need to define this data frame in your R Markdown document, even though the next exercise doesn’t explicitly ask you to do so.

  1. Create a faceted bar plot visualizing the relationship between the category of prize and whether the laureate was in the US when they won the nobel prize. Note: Your visualization should be faceted by category. For each facet you should have two bars, one for winners in the US and one for Other. Flip the coordinates so the bars are horizontal, not vertical. Interpret your visualization, and say a few words about whether the Buzzfeed headline is supported by the data.

✅ ⬆️ Commit and push your changes to GitHub with an appropriate commit message again. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards.

But of those US-based Nobel laureates, many were born in other countries

Hint: You should be able to cheat borrow from code you used earlier to create the country_us variable.

  1. Create a new variable called born_country_us that has the value "USA" if the laureate is born in the US, and "Other" otherwise.

  2. Add a second variable to your visualization from Exercise 3 based on whether the laureate was born in the US or not. Your final visualization should contain a facet for each category, within each facet a bar for whether they won the award in the US or not, and within each bar whether they were born in the US or not. Based on your visualization, do the data appear to support Buzzfeed’s claim? Explain your reasoning in 1-2 sentences.

✅ ⬆️ Commit and push your changes to GitHub with an appropriate commit message again. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards.

Here’s where those immigrant Nobelists were born

Note that your bar plot won’t exactly match the one from the Buzzfeed article. This is likely because the data has been updated since the article was published.

  1. In a single pipeline, filter for laureates who won their prize in the US, but were born outside of the US, and then create a frequency table (with the count()) function for their birth country, born_country, and arrange the resulting data frame in descending order of number of observations for each country.

✅ ⬆️ Commit and push your changes to GitHub with an appropriate commit message again. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards.

Wrapping up

Go back through your write up to make sure you’re following coding style guidelines we discussed in class. Make any edits as needed.

Also, make sure all of your R chunks are properly labeled, and your figures are reasonably sized.

Once the team leader for the week pushes their final changes, others should also clone the team repo (or if you’ve already done so, pull on the Git pane) and knit the R Markdown document to confirm that they can reproduce the report.

If you haven’t yet submitted your team name, don’t forget to do so here.

Interested in how Buzzfeed made their visualizations?

The plots in the Buzzfeed article are called waffle plots. You can find the code used for making these plots in Buzzfeed’s GitHub repo (yes, they have one!) here. You’re not expected to recreate them as part of your assignment, but you’re welcomed to do so for fun!