Nobel Prize API

Author

Guibril Ramde

##Approach

In this assignment, I will use the Nobel Prize API to retrieve JSON data about Nobel laureates and prizes. The main endpoint I will use is the Laureates API, which returns information about individuals and organizations connected to Nobel Prizes. I may also use the Nobel Prizes endpoint if needed for prize-level comparisons. The Nobel Prize Developer Zone provides both of these public endpoints in API version 2.1

After retrieving the JSON data in R, I will transform the nested response into tidy data frames using packages such as `jsonlite`, `httr`, `dplyr`, `tidyr`, and `janitor`. I will then explore the cleaned data to answer four data-driven questions about Nobel laureates.

The four questions I plan to investigate are:

  • Which countries have produced the highest number of Nobel laureates??

  • Which country has lost the most Nobel laureates, meaning laureates who were born there but received the prize as citizens of another country?

  • Have any individuals won the Nobel Prize more than once?

  • What age group is most common among Nobel laureates at the time they received the prize?

    For each question, I will describe the question, show the R code used to answer it, and present the result using a table, summary, or visualization.

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tibble' was built under R version 4.5.2
Warning: package 'tidyr' was built under R version 4.5.2
Warning: package 'readr' was built under R version 4.5.2
Warning: package 'purrr' was built under R version 4.5.2
Warning: package 'dplyr' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(readr)
library(jsonlite)

Attaching package: 'jsonlite'

The following object is masked from 'package:purrr':

    flatten
library(httr)
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(ggplot2)


url <- "https://api.nobelprize.org/2.1/laureates"

response <- GET(url)
stop_for_status(response)

raw_text <- content(response, as = "text", encoding = "UTF-8")
data <- fromJSON(raw_text, flatten = TRUE)


names(data)
[1] "laureates" "meta"      "links"    
glimpse(data)
List of 3
 $ laureates:'data.frame':  25 obs. of  70 variables:
  ..$ id                              : chr [1:25] "745" "102" "779" "259" ...
  ..$ fileName                        : chr [1:25] "spence" "bohr" "ciechanover" "klug" ...
  ..$ gender                          : chr [1:25] "male" "male" "male" "male" ...
  ..$ sameAs                          :List of 25
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q157245" "https://en.wikipedia.org/wiki/Michael_Spence"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q103854" "https://en.wikipedia.org/wiki/Aage_Bohr"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q233205" "https://en.wikipedia.org/wiki/Aaron_Ciechanover"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q190626" "https://en.wikipedia.org/wiki/Aaron_Klug"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q317877" "https://en.wikipedia.org/wiki/Abdulrazak_Gurnah"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q28189" "https://en.wikipedia.org/wiki/Abdus_Salam"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q320578" "https://en.wikipedia.org/wiki/Abhijit_Banerjee"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q50365049" "https://en.wikipedia.org/wiki/Abiy_Ahmed"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q7426" "https://en.wikipedia.org/wiki/Ada_Yonath"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q106454" "https://en.wikipedia.org/wiki/Adam_Riess"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q5327" "https://en.wikipedia.org/wiki/Adolf_Butenandt"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q57078" "https://en.wikipedia.org/wiki/Adolf_von_Baeyer"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q77142" "https://en.wikipedia.org/wiki/Adolf_Otto_Reinhold_Windaus"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q206505" "https://en.wikipedia.org/wiki/Adolfo_Pérez_Esquivel"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q106624" "https://en.wikipedia.org/wiki/Ahmed_Zewail"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q105949" "https://en.wikipedia.org/wiki/Akira_Suzuki_(chemist)"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q4701206" "https://en.wikipedia.org/wiki/Akira_Yoshino"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q19673" "https://en.wikipedia.org/wiki/Al_Gore"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q364997" "https://en.wikipedia.org/wiki/Alain_Aspect"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q106751" "https://en.wikipedia.org/wiki/Alan_J._Heeger"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q193650" "https://en.wikipedia.org/wiki/Alan_Lloyd_Hodgkin"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q110942" "https://en.wikipedia.org/wiki/Alan_MacDiarmid"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q127234" "https://en.wikipedia.org/wiki/Albert_Abraham_Michelson"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q34670" "https://en.wikipedia.org/wiki/Albert_Camus"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q233943" "https://en.wikipedia.org/wiki/Albert_Claude"
  ..$ links                           :List of 25
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  .. ..$ :'data.frame': 2 obs. of  6 variables:
  ..$ nobelPrizes                     :List of 25
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  15 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  16 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  .. ..$ :'data.frame': 1 obs. of  17 variables:
  ..$ knownName.en                    : chr [1:25] "A. Michael Spence" "Aage N. Bohr" "Aaron Ciechanover" "Aaron Klug" ...
  ..$ knownName.se                    : chr [1:25] "A. Michael Spence" "Aage N. Bohr" "Aaron Ciechanover" "Aaron Klug" ...
  ..$ givenName.en                    : chr [1:25] "A. Michael" "Aage N." "Aaron" "Aaron" ...
  ..$ givenName.se                    : chr [1:25] "A. Michael" "Aage N." "Aaron" "Aaron" ...
  ..$ familyName.en                   : chr [1:25] "Spence" "Bohr" "Ciechanover" "Klug" ...
  ..$ familyName.se                   : chr [1:25] "Spence" "Bohr" "Ciechanover" "Klug" ...
  ..$ fullName.en                     : chr [1:25] "A. Michael Spence" "Aage Niels Bohr" "Aaron Ciechanover" "Aaron Klug" ...
  ..$ fullName.se                     : chr [1:25] "A. Michael Spence" "Aage Niels Bohr" "Aaron Ciechanover" "Aaron Klug" ...
  ..$ birth.date                      : chr [1:25] "1943-00-00" "1922-06-19" "1947-10-01" "1926-08-11" ...
  ..$ birth.year                      : chr [1:25] "1943" "1922" "1947" "1926" ...
  ..$ birth.place.city.en             : chr [1:25] "Montclair, NJ" "Copenhagen" "Haifa" "Zelvas" ...
  ..$ birth.place.city.no             : chr [1:25] "Montclair, NJ" "København" "Haifa" "Zelvas" ...
  ..$ birth.place.city.se             : chr [1:25] "Montclair, NJ" "Köpenhamn" "Haifa" "Zelvas" ...
  ..$ birth.place.country.en          : chr [1:25] "USA" "Denmark" "British Protectorate of Palestine" "Lithuania" ...
  ..$ birth.place.country.no          : chr [1:25] "USA" "Danmark" "British i Palestina" "Litauen" ...
  ..$ birth.place.country.se          : chr [1:25] "USA" "Danmark" "British Protectorate of Palestine" "Litauen" ...
  ..$ birth.place.cityNow.en          : chr [1:25] "Montclair, NJ" "Copenhagen" "Haifa" "Zelvas" ...
  ..$ birth.place.cityNow.no          : chr [1:25] "Montclair, NJ" "København" "Haifa" "Zelvas" ...
  ..$ birth.place.cityNow.se          : chr [1:25] "Montclair, NJ" "Köpenhamn" "Haifa" "Zelvas" ...
  ..$ birth.place.cityNow.sameAs      :List of 25
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q678437" "https://www.wikipedia.org/wiki/Montclair,_New_Jersey"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1748" "https://www.wikipedia.org/wiki/Copenhagen"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q41621" "https://www.wikipedia.org/wiki/Haifa"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q691679" "https://www.wikipedia.org/wiki/%C5%BDelva"
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1026616" "https://www.wikipedia.org/wiki/Jhang"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1156" "https://www.wikipedia.org/wiki/Mumbai"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q2899862" "https://www.wikipedia.org/wiki/Beshasha"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1218" "https://www.wikipedia.org/wiki/Jerusalem"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q61" "https://www.wikipedia.org/wiki/Washington,_D.C."
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q2706" "https://www.wikipedia.org/wiki/Bremerhaven"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q64" "https://www.wikipedia.org/wiki/Berlin"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q64" "https://www.wikipedia.org/wiki/Berlin"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1486" "https://www.wikipedia.org/wiki/Buenos_Aires"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q328153" "https://www.wikipedia.org/wiki/Damanhur"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1187152" "https://www.wikipedia.org/wiki/Mukawa,_Hokkaido"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q653510" "https://www.wikipedia.org/wiki/Suita"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q61" "https://www.wikipedia.org/wiki/Washington,_D.C."
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q6625" "https://www.wikipedia.org/wiki/Agen"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q489255" "https://www.wikipedia.org/wiki/Sioux_City,_Iowa"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q806160" "https://www.wikipedia.org/wiki/Banbury"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1223916" "https://www.wikipedia.org/wiki/Masterton"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1005414" "https://www.wikipedia.org/wiki/Strzelno"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1924629" "https://www.wikipedia.org/wiki/Dr%C3%A9an"
  .. ..$ : NULL
  ..$ birth.place.cityNow.latitude    : chr [1:25] "40.825930" "55.678127" "32.794421" "53.148256" ...
  ..$ birth.place.cityNow.longitude   : chr [1:25] "-74.209030" "12.572532" "34.990340" "24.816515" ...
  ..$ birth.place.countryNow.en       : chr [1:25] "USA" "Denmark" "Israel" "Lithuania" ...
  ..$ birth.place.countryNow.no       : chr [1:25] "USA" "Danmark" "Israel" "Litauen" ...
  ..$ birth.place.countryNow.se       : chr [1:25] "USA" "Danmark" "Israel" "Litauen" ...
  ..$ birth.place.countryNow.sameAs   :List of 25
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q35"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q801"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q37"
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q843"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q668"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q115"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q801"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q414"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q79"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q17"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q17"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q142"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q145"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q664"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q36"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q262"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q31"
  ..$ birth.place.countryNow.latitude : chr [1:25] "39.828175" "56.000000" "31.000000" "55.200000" ...
  ..$ birth.place.countryNow.longitude: chr [1:25] "-98.579500" "10.000000" "35.000000" "24.000000" ...
  ..$ birth.place.continent.en        : chr [1:25] "North America" "Europe" "Asia" "Europe" ...
  ..$ birth.place.continent.no        : chr [1:25] "Nord-Amerika" "Europa" "Asia" "Europa" ...
  ..$ birth.place.continent.se        : chr [1:25] "Nordamerika" "Europa" "Asien" "Europa" ...
  ..$ birth.place.locationString.en   : chr [1:25] "Montclair, NJ, USA" "Copenhagen, Denmark" "Haifa, British Protectorate of Palestine (now Israel)" "Zelvas, Lithuania" ...
  ..$ birth.place.locationString.no   : chr [1:25] "Montclair, NJ, USA" "København, Danmark" "Haifa, British i Palestina (nå Israel)" "Zelvas, Litauen" ...
  ..$ birth.place.locationString.se   : chr [1:25] "Montclair, NJ, USA" "Köpenhamn, Danmark" "Haifa, British Protectorate of Palestine (nu Israel)" "Zelvas, Litauen" ...
  ..$ wikipedia.slug                  : chr [1:25] "Michael_Spence" "Aage_Bohr" "Aaron_Ciechanover" "Aaron_Klug" ...
  ..$ wikipedia.english               : chr [1:25] "https://en.wikipedia.org/wiki/Michael_Spence" "https://en.wikipedia.org/wiki/Aage_Bohr" "https://en.wikipedia.org/wiki/Aaron_Ciechanover" "https://en.wikipedia.org/wiki/Aaron_Klug" ...
  ..$ wikidata.id                     : chr [1:25] "Q157245" "Q103854" "Q233205" "Q190626" ...
  ..$ wikidata.url                    : chr [1:25] "https://www.wikidata.org/wiki/Q157245" "https://www.wikidata.org/wiki/Q103854" "https://www.wikidata.org/wiki/Q233205" "https://www.wikidata.org/wiki/Q190626" ...
  ..$ death.date                      : chr [1:25] NA "2009-09-08" NA "2018-11-20" ...
  ..$ death.place.city.en             : chr [1:25] NA "Copenhagen" NA NA ...
  ..$ death.place.city.no             : chr [1:25] NA "København" NA NA ...
  ..$ death.place.city.se             : chr [1:25] NA "Köpenhamn" NA NA ...
  ..$ death.place.country.en          : chr [1:25] NA "Denmark" NA NA ...
  ..$ death.place.country.no          : chr [1:25] NA "Danmark" NA NA ...
  ..$ death.place.country.se          : chr [1:25] NA "Danmark" NA NA ...
  ..$ death.place.country.sameAs      : chr [1:25] NA "https://www.wikidata.org/wiki/Q35" NA NA ...
  ..$ death.place.cityNow.en          : chr [1:25] NA "Copenhagen" NA NA ...
  ..$ death.place.cityNow.no          : chr [1:25] NA "København" NA NA ...
  ..$ death.place.cityNow.se          : chr [1:25] NA "Köpenhamn" NA NA ...
  ..$ death.place.cityNow.sameAs      :List of 25
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1748" "https://www.wikipedia.org/wiki/Copenhagen"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q34217" "https://www.wikipedia.org/wiki/Oxford"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1726" "https://www.wikipedia.org/wiki/Munich"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q61936" "https://www.wikipedia.org/wiki/Starnberg"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q3033" "https://www.wikipedia.org/wiki/G%C3%B6ttingen"
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q485176" "https://www.wikipedia.org/wiki/Pasadena,_California"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q350" "https://www.wikipedia.org/wiki/Cambridge"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q1132763" "https://www.wikipedia.org/wiki/Drexel_Hill,_Pennsylvania"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q485176" "https://www.wikipedia.org/wiki/Pasadena,_California"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q212420" "https://www.wikipedia.org/wiki/Sens"
  .. ..$ : chr [1:2] "https://www.wikidata.org/wiki/Q239" "https://www.wikipedia.org/wiki/City_of_Brussels"
  ..$ death.place.cityNow.latitude    : chr [1:25] NA "55.678127" NA NA ...
  ..$ death.place.cityNow.longitude   : chr [1:25] NA "12.572532" NA NA ...
  ..$ death.place.countryNow.en       : chr [1:25] NA "Denmark" NA NA ...
  ..$ death.place.countryNow.no       : chr [1:25] NA "Danmark" NA NA ...
  ..$ death.place.countryNow.se       : chr [1:25] NA "Danmark" NA NA ...
  ..$ death.place.countryNow.sameAs   :List of 25
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q35"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q145"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q183"
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : NULL
  .. ..$ : chr "https://www.wikidata.org/wiki/Q145"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q30"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q142"
  .. ..$ : chr "https://www.wikidata.org/wiki/Q31"
  ..$ death.place.countryNow.latitude : chr [1:25] NA "56.000000" NA NA ...
  ..$ death.place.countryNow.longitude: chr [1:25] NA "10.000000" NA NA ...
  ..$ death.place.continent.en        : chr [1:25] NA "Europe" NA NA ...
  ..$ death.place.continent.no        : chr [1:25] NA "Europa" NA NA ...
  ..$ death.place.continent.se        : chr [1:25] NA "Europa" NA NA ...
  ..$ death.place.locationString.en   : chr [1:25] NA "Copenhagen, Denmark" NA "" ...
  ..$ death.place.locationString.no   : chr [1:25] NA "København, Danmark" NA "" ...
  ..$ death.place.locationString.se   : chr [1:25] NA "Köpenhamn, Danmark" NA "" ...
 $ meta     :List of 6
  ..$ offset    : int 0
  ..$ limit     : int 25
  ..$ count     : int 1018
  ..$ terms     : chr "https://www.nobelprize.org/about/terms-of-use-for-api-nobelprize-org-and-data-nobelprize-org/"
  ..$ license   : chr "https://www.nobelprize.org/about/terms-of-use-for-api-nobelprize-org-and-data-nobelprize-org/#licence"
  ..$ disclaimer: chr "https://www.nobelprize.org/about/terms-of-use-for-api-nobelprize-org-and-data-nobelprize-org/#disclaimer"
 $ links    :List of 4
  ..$ first: chr "http://nobel-external-api-app.azurewebsites.net/2.1/laureates?offset=0&limit=25"
  ..$ self : chr "http://nobel-external-api-app.azurewebsites.net/2.1/laureates?offset=0&limit=25"
  ..$ next : chr "http://nobel-external-api-app.azurewebsites.net/2.1/laureates?offset=25&limit=25"
  ..$ last : chr "http://nobel-external-api-app.azurewebsites.net/2.1/laureates?offset=1000&limit=25"
laureates <- as_tibble(data$laureates) |>
  clean_names()

glimpse(laureates)
Rows: 25
Columns: 70
$ id                                <chr> "745", "102", "779", "259", "1004", …
$ file_name                         <chr> "spence", "bohr", "ciechanover", "kl…
$ gender                            <chr> "male", "male", "male", "male", "mal…
$ same_as                           <list> <"https://www.wikidata.org/wiki/Q15…
$ links                             <list> [<data.frame[2 x 6]>], [<data.frame…
$ nobel_prizes                      <list> [<data.frame[1 x 17]>], [<data.fram…
$ known_name_en                     <chr> "A. Michael Spence", "Aage N. Bohr",…
$ known_name_se                     <chr> "A. Michael Spence", "Aage N. Bohr",…
$ given_name_en                     <chr> "A. Michael", "Aage N.", "Aaron", "A…
$ given_name_se                     <chr> "A. Michael", "Aage N.", "Aaron", "A…
$ family_name_en                    <chr> "Spence", "Bohr", "Ciechanover", "Kl…
$ family_name_se                    <chr> "Spence", "Bohr", "Ciechanover", "Kl…
$ full_name_en                      <chr> "A. Michael Spence", "Aage Niels Boh…
$ full_name_se                      <chr> "A. Michael Spence", "Aage Niels Boh…
$ birth_date                        <chr> "1943-00-00", "1922-06-19", "1947-10…
$ birth_year                        <chr> "1943", "1922", "1947", "1926", "194…
$ birth_place_city_en               <chr> "Montclair, NJ", "Copenhagen", "Haif…
$ birth_place_city_no               <chr> "Montclair, NJ", "København", "Haifa…
$ birth_place_city_se               <chr> "Montclair, NJ", "Köpenhamn", "Haifa…
$ birth_place_country_en            <chr> "USA", "Denmark", "British Protector…
$ birth_place_country_no            <chr> "USA", "Danmark", "British i Palesti…
$ birth_place_country_se            <chr> "USA", "Danmark", "British Protector…
$ birth_place_city_now_en           <chr> "Montclair, NJ", "Copenhagen", "Haif…
$ birth_place_city_now_no           <chr> "Montclair, NJ", "København", "Haifa…
$ birth_place_city_now_se           <chr> "Montclair, NJ", "Köpenhamn", "Haifa…
$ birth_place_city_now_same_as      <list> <"https://www.wikidata.org/wiki/Q67…
$ birth_place_city_now_latitude     <chr> "40.825930", "55.678127", "32.794421…
$ birth_place_city_now_longitude    <chr> "-74.209030", "12.572532", "34.99034…
$ birth_place_country_now_en        <chr> "USA", "Denmark", "Israel", "Lithuan…
$ birth_place_country_now_no        <chr> "USA", "Danmark", "Israel", "Litauen…
$ birth_place_country_now_se        <chr> "USA", "Danmark", "Israel", "Litauen…
$ birth_place_country_now_same_as   <list> "https://www.wikidata.org/wiki/Q30"…
$ birth_place_country_now_latitude  <chr> "39.828175", "56.000000", "31.000000…
$ birth_place_country_now_longitude <chr> "-98.579500", "10.000000", "35.00000…
$ birth_place_continent_en          <chr> "North America", "Europe", "Asia", "…
$ birth_place_continent_no          <chr> "Nord-Amerika", "Europa", "Asia", "E…
$ birth_place_continent_se          <chr> "Nordamerika", "Europa", "Asien", "E…
$ birth_place_location_string_en    <chr> "Montclair, NJ, USA", "Copenhagen, D…
$ birth_place_location_string_no    <chr> "Montclair, NJ, USA", "København, Da…
$ birth_place_location_string_se    <chr> "Montclair, NJ, USA", "Köpenhamn, Da…
$ wikipedia_slug                    <chr> "Michael_Spence", "Aage_Bohr", "Aaro…
$ wikipedia_english                 <chr> "https://en.wikipedia.org/wiki/Micha…
$ wikidata_id                       <chr> "Q157245", "Q103854", "Q233205", "Q1…
$ wikidata_url                      <chr> "https://www.wikidata.org/wiki/Q1572…
$ death_date                        <chr> NA, "2009-09-08", NA, "2018-11-20", …
$ death_place_city_en               <chr> NA, "Copenhagen", NA, NA, NA, "Oxfor…
$ death_place_city_no               <chr> NA, "København", NA, NA, NA, "Oxford…
$ death_place_city_se               <chr> NA, "Köpenhamn", NA, NA, NA, "Oxford…
$ death_place_country_en            <chr> NA, "Denmark", NA, NA, NA, "United K…
$ death_place_country_no            <chr> NA, "Danmark", NA, NA, NA, "Storbrit…
$ death_place_country_se            <chr> NA, "Danmark", NA, NA, NA, "Storbrit…
$ death_place_country_same_as       <chr> NA, "https://www.wikidata.org/wiki/Q…
$ death_place_city_now_en           <chr> NA, "Copenhagen", NA, NA, NA, "Oxfor…
$ death_place_city_now_no           <chr> NA, "København", NA, NA, NA, "Oxford…
$ death_place_city_now_se           <chr> NA, "Köpenhamn", NA, NA, NA, "Oxford…
$ death_place_city_now_same_as      <list> <NULL>, <"https://www.wikidata.org/…
$ death_place_city_now_latitude     <chr> NA, "55.678127", NA, NA, NA, "51.753…
$ death_place_city_now_longitude    <chr> NA, "12.572532", NA, NA, NA, "-1.260…
$ death_place_country_now_en        <chr> NA, "Denmark", NA, NA, NA, "United K…
$ death_place_country_now_no        <chr> NA, "Danmark", NA, NA, NA, "Storbrit…
$ death_place_country_now_se        <chr> NA, "Danmark", NA, NA, NA, "Storbrit…
$ death_place_country_now_same_as   <list> <NULL>, "https://www.wikidata.org/w…
$ death_place_country_now_latitude  <chr> NA, "56.000000", NA, NA, NA, "54.600…
$ death_place_country_now_longitude <chr> NA, "10.000000", NA, NA, NA, "-2.000…
$ death_place_continent_en          <chr> NA, "Europe", NA, NA, NA, "Europe", …
$ death_place_continent_no          <chr> NA, "Europa", NA, NA, NA, "Europa", …
$ death_place_continent_se          <chr> NA, "Europa", NA, NA, NA, "Europa", …
$ death_place_location_string_en    <chr> NA, "Copenhagen, Denmark", NA, "", N…
$ death_place_location_string_no    <chr> NA, "København, Danmark", NA, "", NA…
$ death_place_location_string_se    <chr> NA, "Köpenhamn, Danmark", NA, "", NA…

##Which countries have produced the highest number of Nobel laureates?

laureates |>
  drop_na()
# A tibble: 9 × 70
  id    file_name  gender same_as links nobel_prizes known_name_en known_name_se
  <chr> <chr>      <chr>  <list>  <lis> <list>       <chr>         <chr>        
1 102   bohr       male   <chr>   <df>  <df>         Aage N. Bohr  Aage N. Bohr 
2 114   salam      male   <chr>   <df>  <df>         Abdus Salam   Abdus Salam  
3 199   butenandt  male   <chr>   <df>  <df>         Adolf Butena… Adolf Butena…
4 164   baeyer     male   <chr>   <df>  <df>         Adolf von Ba… Adolf von Ba…
5 292   zewail     male   <chr>   <df>  <df>         Ahmed Zewail  Ahmed Zewail 
6 376   hodgkin    male   <chr>   <df>  <df>         Alan Hodgkin  Alan Hodgkin 
7 730   macdiarmid male   <chr>   <df>  <df>         Alan MacDiar… Alan MacDiar…
8 11    michelson  male   <chr>   <df>  <df>         Albert A. Mi… Albert A. Mi…
9 628   camus      male   <chr>   <df>  <df>         Albert Camus  Albert Camus 
# ℹ 62 more variables: given_name_en <chr>, given_name_se <chr>,
#   family_name_en <chr>, family_name_se <chr>, full_name_en <chr>,
#   full_name_se <chr>, birth_date <chr>, birth_year <chr>,
#   birth_place_city_en <chr>, birth_place_city_no <chr>,
#   birth_place_city_se <chr>, birth_place_country_en <chr>,
#   birth_place_country_no <chr>, birth_place_country_se <chr>,
#   birth_place_city_now_en <chr>, birth_place_city_now_no <chr>, …
laureates |>
  filter(!is.na(birth_place_country_en)) |>
  count(birth_place_country_en, sort = TRUE)
# A tibble: 17 × 2
   birth_place_country_en                n
   <chr>                             <int>
 1 USA                                   4
 2 Germany                               2
 3 India                                 2
 4 Japan                                 2
 5 Prussia                               2
 6 Argentina                             1
 7 Belgium                               1
 8 British Mandate of Palestine          1
 9 British Protectorate of Palestine     1
10 Denmark                               1
11 Egypt                                 1
12 Ethiopia                              1
13 France                                1
14 French Algeria                        1
15 Lithuania                             1
16 New Zealand                           1
17 United Kingdom                        1
library(ggplot2)

country_counts <- laureates |>
  filter(!is.na(birth_place_country_en)) |>
  count(birth_place_country_en, sort = TRUE) |>
  slice_head(n = 10)

ggplot(data = country_counts, 
       aes(x = reorder(birth_place_country_en, n), y = n, fill = birth_place_country_en) ) +
  geom_col() +
  coord_flip() +
  labs(
    title = "Top 10 Countries by Number of Nobel Laureates",
    x = "Country",
    y = "Number of Laureates"
  ) +
  theme(legend.position = "none")

##Using a map for better visualization

#install.packages("rnaturalearth")
#install.packages("rnaturalearthdata")
library(tidyverse)
library(sf)
Warning: package 'sf' was built under R version 4.5.2
Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
library(rnaturalearth)
Warning: package 'rnaturalearth' was built under R version 4.5.2
library(rnaturalearthdata)

Attaching package: 'rnaturalearthdata'
The following object is masked from 'package:rnaturalearth':

    countries110
world <- ne_countries(scale = "medium", returnclass = "sf")

country_counts <- laureates |>
  filter(!is.na(birth_place_country_now_en)) |>
  count(birth_place_country_now_en, sort = TRUE)

world_nobel <- world |>
  mutate(name = str_trim(name)) |>
  left_join(
    country_counts,
    by = c("name" = "birth_place_country_now_en")
  )

ggplot(world_nobel) +
  geom_sf(aes(fill = n), color = "gray80", linewidth = 0.2) +
  scale_fill_viridis_c(na.value = "white") +
  labs(
    title = "World Map of Nobel Laureates by Birth Country",
    fill = "Count"
  ) +
  theme_void()

##Which country has lost the most Nobel laureates, meaning laureates who were born there but received the prize as citizens of another country?

The previous bar chart and map show the countries where Nobel laureates were born, which answers the first question. To answer the second question, I compare each laureate’s birth country with the country of affiliation at the time of the award. This helps identify countries that “lost” laureates, meaning individuals who were born in one country but received the prize while affiliated with another.

library(tidyverse)

laureates_step1 <- laureates |>
  select(id, full_name_en, birth_place_country_now_en, nobel_prizes) |>
  unnest(nobel_prizes) |>
  unnest(affiliations)
glimpse(laureates_step1)
Rows: 25
Columns: 47
$ id                         <chr> "745", "102", "779", "259", "114", "114", "…
$ full_name_en               <chr> "A. Michael Spence", "Aage Niels Bohr", "Aa…
$ birth_place_country_now_en <chr> "USA", "Denmark", "Israel", "Lithuania", "P…
$ awardYear                  <chr> "2001", "1975", "2004", "1982", "1979", "19…
$ sortOrder                  <chr> "2", "1", "1", "1", "2", "2", "1", "3", "3"…
$ portion                    <chr> "1/3", "1/3", "1/3", "1", "1/3", "1/3", "1/…
$ dateAwarded                <chr> "2001-10-10", "1975-10-17", "2004-10-06", "…
$ prizeStatus                <chr> "received", "received", "received", "receiv…
$ prizeAmount                <int> 10000000, 630000, 10000000, 1150000, 800000…
$ prizeAmountAdjusted        <int> 15547541, 4304697, 14874529, 3923237, 37784…
$ name.en                    <chr> "Stanford University", "Niels Bohr Institut…
$ name.no                    <chr> "Stanford University", "Niels Bohr Institut…
$ name.se                    <chr> "Stanford University", "Niels Bohr Institut…
$ nameNow.en                 <chr> "Stanford University", "Niels Bohr Institut…
$ city.en                    <chr> "Stanford, CA", "Copenhagen", "Haifa", "Cam…
$ city.no                    <chr> "Stanford, CA", "København", "Haifa", "Camb…
$ city.se                    <chr> "Stanford, CA", "Köpenhamn", "Haifa", "Camb…
$ country.en                 <chr> "USA", "Denmark", "Israel", "United Kingdom…
$ country.no                 <chr> "USA", "Danmark", "Israel", "Storbritannia"…
$ country.se                 <chr> "USA", "Danmark", "Israel", "Storbritannien…
$ cityNow.en                 <chr> "Stanford, CA", "Copenhagen", "Haifa", "Cam…
$ cityNow.no                 <chr> "Stanford, CA", "København", "Haifa", "Camb…
$ cityNow.se                 <chr> "Stanford, CA", "Köpenhamn", "Haifa", "Camb…
$ cityNow.sameAs             <list> <"https://www.wikidata.org/wiki/Q173813", …
$ cityNow.latitude           <chr> "37.424734", "55.678127", "32.794421", "52.…
$ cityNow.longitude          <chr> "-122.163858", "12.572532", "34.990340", "0…
$ countryNow.en              <chr> "USA", "Denmark", "Israel", "United Kingdom…
$ countryNow.no              <chr> "USA", "Danmark", "Israel", "Storbritannia"…
$ countryNow.se              <chr> "USA", "Danmark", "Israel", "Storbritannien…
$ countryNow.sameAs          <list> "https://www.wikidata.org/wiki/Q30", "http…
$ countryNow.latitude        <chr> "39.828175", "56.000000", "31.000000", "54.…
$ countryNow.longitude       <chr> "-98.579500", "10.000000", "35.000000", "-2…
$ continent.en               <chr> "North America", "Europe", "Asia", "Europe"…
$ locationString.en          <chr> "Stanford, CA, USA", "Copenhagen, Denmark",…
$ locationString.no          <chr> "Stanford, CA, USA", "København, Danmark", …
$ locationString.se          <chr> "Stanford, CA, USA", "Köpenhamn, Danmark", …
$ links                      <list> [<data.frame[3 x 6]>], [<data.frame[3 x 6]…
$ category.en                <chr> "Economic Sciences", "Physics", "Chemistry"…
$ category.no                <chr> "Økonomi", "Fysikk", "Kjemi", "Kjemi", "Fys…
$ category.se                <chr> "Ekonomi", "Fysik", "Kemi", "Kemi", "Fysik"…
$ categoryFullName.en        <chr> "The Sveriges Riksbank Prize in Economic Sc…
$ categoryFullName.no        <chr> "Sveriges Riksbanks pris i økonomisk vitens…
$ categoryFullName.se        <chr> "Sveriges Riksbanks pris i ekonomisk vetens…
$ motivation.en              <chr> "for their analyses of markets with asymmet…
$ motivation.se              <chr> "för deras analys av marknader med assymetr…
$ motivation.no              <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ residences                 <list> <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <N…
comparison <- laureates |>
  select(id, full_name_en, birth_place_country_now_en, nobel_prizes) |>
  unnest(nobel_prizes) |>
  unnest(affiliations) |>
  filter(!is.na(birth_place_country_now_en),
         !is.na(country.en)) |>
  mutate(
    birth_country = birth_place_country_now_en,
    award_country = country.en
  )
movers <- comparison |>
  filter(birth_country != award_country)

movers |>
  count(birth_country, sort = TRUE)
# A tibble: 6 × 2
  birth_country     n
  <chr>         <int>
1 Pakistan          2
2 Egypt             1
3 India             1
4 Lithuania         1
5 New Zealand       1
6 Poland            1
movers |>
  count(birth_country, sort = TRUE) |>
  slice_head(n = 10) |>
  ggplot(aes(x = reorder(birth_country, n), y = n)) +
  geom_col(fill = "steelblue") +
  coord_flip() +
  labs(
    title = "Top Birth Countries Losing Nobel Laureates",
    x = "Birth Country",
    y = "Number of Laureates"
  ) +
  theme_minimal()

This chart shows the countries of birth for laureates who later received the Nobel Prize while affiliated with a different country. A higher count suggests that more laureates born in that country later worked elsewhere at the time of their award.

#install.packages("networkD3")
library(networkD3)
library(dplyr)

flows <- comparison |>
  count(birth_country, award_country, sort = TRUE) |>
  filter(birth_country != award_country)

nodes <- data.frame(
  name = unique(c(flows$birth_country, flows$award_country))
)

flows <- flows |>
  mutate(
    source = match(birth_country, nodes$name) - 1,
    target = match(award_country, nodes$name) - 1
  )

sankeyNetwork(
  Links = flows,
  Nodes = nodes,
  Source = "source",
  Target = "target",
  Value = "n",
  NodeID = "name",
  fontSize = 12
)
Links is a tbl_df. Converting to a plain data frame.

To better understand the movement of Nobel laureates between countries, I used a Sankey diagram to visualize the flow from birth country to the country of affiliation at the time of the award. This allows us to clearly observe migration patterns and identify which countries attract or lose talent

##Have any individuals won the Nobel Prize more than once?

laureates_prizes <- laureates |>
  select(id, full_name_en, nobel_prizes) |>
  unnest(nobel_prizes)
multi_awarded <- laureates_prizes |>
  count(id, full_name_en, sort = TRUE)

multi_awarded |>
  filter(n > 1)
# A tibble: 0 × 3
# ℹ 3 variables: id <chr>, full_name_en <chr>, n <int>

To determine whether any individuals have won the Nobel Prize more than once, I unnested the `nobel_prizes` field and counted the number of prizes associated with each laureate. In the data retrieved for this analysis, no individual appears more than once.

##What age group is most common among Nobel laureates at the time they received the prize?

laureates_age <- laureates |>
  select(id, full_name_en, birth_year, nobel_prizes) |>
  unnest(nobel_prizes) |>
  filter(!is.na(birth_year), !is.na(awardYear)) |>
  mutate(
    birth_year = as.numeric(birth_year),
    awardYear = as.numeric(awardYear),
    age_at_award = awardYear - birth_year,
    age_group = case_when(
      age_at_award < 40 ~ "Under 40",
      age_at_award >= 40 & age_at_award < 50 ~ "40-49",
      age_at_award >= 50 & age_at_award < 60 ~ "50-59",
      age_at_award >= 60 & age_at_award < 70 ~ "60-69",
      age_at_award >= 70 ~ "70+",
      TRUE ~ NA_character_
    )
  )

laureates_age |>
  count(age_group, sort = TRUE)
# A tibble: 5 × 2
  age_group     n
  <chr>     <int>
1 50-59        10
2 70+           8
3 40-49         5
4 60-69         1
5 Under 40      1
laureates_age |>
  count(age_group, sort = TRUE) |>
  ggplot(aes(x = reorder(age_group, n), y = n)) +
  geom_col(fill = "steelblue") +
  labs(
    title = "Most Common Age Groups at Time of Nobel Prize Award",
    x = "Age Group",
    y = "Number of Laureates"
  ) +
  theme_minimal()

Conclusion

This assignment was both challenging and informative. By working with the Nobel Prize API, I learned how to retrieve and analyze nested JSON data in R, transform it into tidy data frames, and use multiple visualizations to answer meaningful questions. The analysis showed that Nobel Prize data can reveal not only where laureates were born, but also how talent moves across countries over time. Overall, this project improved my understanding of API-based data analysis and data visualization in R.