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

Lab prep

Before the lab, read the Buzzfeed article titled These Nobel Prize Winners Show Why Immigration Is So Important For American Science.

We will replicate parts of this analysis during the lab, so it’s important that you’re familiar with the article ahead of time.

Working collaboratively

For this lab, you will work together using pair programming. Pair programming means that you work together on the same code rather than dividing the exercises up and completing them separately.

One person will be the driver and one person will be the navigator:

If you are working in a group of three, the third person can act as an additional navigator and should stay actively involved in discussing the code and interpreting the results.

Pair programming tips

  • Switch roles regularly. Aim to switch drivers every exercise or every 10–15 minutes.
  • Talk through what you’re doing. The driver should say what they are trying, and the navigator should ask questions and suggest next steps.
  • Don’t take over the keyboard. If you’re the navigator, explain your idea and let the driver implement it.
  • Work on the same problem together. Avoid splitting up the exercises and working independently.
  • Make sure everyone understands the code. Before moving on, check that everyone on the team can follow what the code is doing.
  • Ask for help early. If your team gets stuck, don’t spend too long trying random solutions before asking a question.

Getting started

Open the project for this lab in the course Posit Cloud workspace.

Open the Quarto document lab-03.qmd and render it before making any changes. Make sure the document renders without errors.

This first render is a useful check that the project, packages, data, and files are all working correctly.

Warm up

Before we introduce the data:

🧶 ✅ Throughout this lab, remember to render your document regularly. After rendering, check the output to make sure your code, figures, and written responses appear as you expect.

Packages

We’ll use the tidyverse package for much of the data wrangling.

library(tidyverse)

Data

The dataset for this assignment can be found as a CSV (comma-separated values) file in the data folder of your project.

You can read it in using:

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

The variable descriptions are as follows:

In a few cases the name of the city/country changed after the laureate was given the award (e.g. in 1975 Bosnia and Herzegovina was called the Socialist Federative Republic of Yugoslavia).

In these cases the variables below reflect a different name than their counterparts without the suffix _original.

Exercises

Work through the exercises collaboratively.

Take turns as the driver and navigator so that each team member has an opportunity to write code. You do not need to switch at every exercise, but try to switch regularly enough that everyone participates in both roles.

The goal is for everyone on the team to understand the code and results, rather than for each person to be responsible for a separate part of the lab.

Get to know your data

  1. ✏️ How many observations and how many variables are in the dataset? Use inline code to answer this question. What does each row represent?

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, once again using inline code.

🧶 ✅ Complete Exercises 1 and 2 and render the document. Check that your written response and inline code appear correctly and that the filtering code produces the expected data frame. This is also a good time to switch driver and navigator roles.

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 is the condition we’re testing for. If country is equal to "USA", we set country_us to "USA". If not, we set 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 if_else() here to show you one example of an if statement in R.

nobel_living <- nobel_living |>
  mutate(
    country_us = if_else(country == "USA", "USA", "Other")
  )

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

nobel_living_science <- nobel_living |>
  filter(category %in% c("Physics", "Medicine", "Chemistry", "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 Quarto 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. Interpret your visualization, and say a few words about whether the Buzzfeed headline is supported by the data.

    • 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.

🧶 ✅ Complete Exercise 3 and render the document. Check that your visualization appears correctly and that your written interpretation addresses the Buzzfeed claim. Switch driver and navigator roles if you haven’t done so recently.

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 was born in the US, and "Other" otherwise. How many of the winners were born in the US?

  2. ✏️ Add a second variable to your visualization from Exercise 3 based on whether the laureate was 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.

    • Your final visualization should contain a facet for each category.
    • Within each facet, there should be a bar for whether the laureate won the award in the US or not.
    • Each bar should have segments for whether the laureate was born in the US or not.

🧶 ✅ Complete Exercises 4 and 5 and render the document. Check that the new variable is created correctly, the updated visualization appears as expected, and both exercises include the requested written responses.

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, 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. Which country is the most common?

🧶 ✅ Complete Exercise 6 and render your document one final time. Read through the rendered document from beginning to end. Make sure all code runs, all figures and output appear correctly, and every exercise marked with ✏️ includes a written response. Designate one person to submit the lab for the team. The other person should submit the name of their team.

Before finishing, check as a team that everyone understands the major steps in the analysis and that each person had an opportunity to work as both driver and navigator.

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!