Show code
# Install packages once if they are missing.
# install.packages(c("httr2", "tidyverse", "jsonlite", "ggplot2", "scales"))This assignment extends practice with JSON and API data with the Nobel Prize API.
API: Application Programming Interface. Set of rules that allows two softwares to communicate, follow rules, and to share data with each other. In this case, requesting data from a website.
API Key: A string of text that acts as a secure passcode for an application to ask a server for the data it is requesting. This is not to be shared with anyone!
Endpoint: A specific digital location or web address where a software application can access the digital resources it needs. Like a library book located in a certain section and we the user want to access and use that book.
Request: The user asking the server if they can extract information without changing anything on the server end.
Response: An answer in the form of status codes (200, 400, etc.) from the server to the user. For this definition, getting a response code of 200 means we are permitted to send a request to the server.
Create an account on the Nobel Prize Developer Size and request an API Key
Create requests to the server to extract data
Parse from JSON format to use in R tibble
Conduct analysis
Creating 4 data-driven questions
Presenting plots or tables to present answers
Interpret the plots and table
# Install packages once if they are missing.
# install.packages(c("httr2", "tidyverse", "jsonlite", "ggplot2", "scales"))library(tidyverse)
library(httr2)
library(jsonlite)
library(ggplot2)
library(scales)Request Parameters
Base URL: https://api.nobelprize.org
Endpoint: /2.1/laureates
With the Nobel Prize API, an API Key is not required so we can simply request data without abusing server requests.
url <- "https://api.nobelprize.org/2.1/laureates"
req <- request(url) |>
req_headers(
`Accept` = "application/json",
`User-Agent` = "DATA607-week10b-homework"
)
req<httr2_request>
GET https://api.nobelprize.org/2.1/laureates
Headers:
* Accept : "application/json"
* User-Agent: "DATA607-week10b-homework"
Body: empty
req_dry_run(req)GET /2.1/laureates HTTP/1.1
accept: application/json
accept-encoding: deflate, gzip
host: api.nobelprize.org
user-agent: DATA607-week10b-homework
resp <- req |>
req_perform()
# Confirm that the server accepted the request.
resp_status(resp)[1] 200
resp_status_desc(resp)[1] "OK"
resp_content_type(resp)[1] "application/json"
nobel_prize_JSON <- resp |>
resp_body_json(simplifyVector = TRUE)
names(nobel_prize_JSON) [1] "laureates" "meta" "links"
# we want to investigate laureates
names(nobel_prize_JSON$laureates) [1] "id" "knownName" "givenName" "familyName" "fullName"
[6] "fileName" "gender" "birth" "wikipedia" "wikidata"
[11] "sameAs" "links" "nobelPrizes" "death"
This part is where we need to decide what columns we want to keep for our data that we want to analyze, I have selected:
id
fullName
gender
birth
nobelPrizes
Note: nobelPrizes also contains data inside the variable itself, so we need to further investigate to see what columns we would also want to extract
nobelPrize ListGiven that we need to unnest nobelPrizes, we need to decide which columns in this new table we have created to keep and to unflatten.
laureates <- nobel_prize_JSON$laureates
prizes <- laureates |>
select(id, fullName, gender, birth, nobelPrizes) |>
unnest(nobelPrizes, names_sep = "_")
glimpse(prizes)Rows: 25
Columns: 17
$ id <chr> "745", "102", "779", "259", "1004", "1…
$ fullName <df[,2]> <data.frame[25 x 2]>
$ gender <chr> "male", "male", "male", "male", "ma…
$ birth <df[,3]> <data.frame[25 x 3]>
$ nobelPrizes_awardYear <chr> "2001", "1975", "2004", "1982", "2021"…
$ nobelPrizes_category <df[,3]> <data.frame[25 x 3]>
$ nobelPrizes_categoryFullName <df[,3]> <data.frame[25 x 3]>
$ nobelPrizes_sortOrder <chr> "2", "1", "1", "1", "1", "2", "1", …
$ nobelPrizes_portion <chr> "1/3", "1/3", "1/3", "1", "1", "1/3", …
$ nobelPrizes_dateAwarded <chr> "2001-10-10", "1975-10-17", "2004-1…
$ nobelPrizes_prizeStatus <chr> "received", "received", "received",…
$ nobelPrizes_motivation <df[,3]> <data.frame[25 x 3]>
$ nobelPrizes_prizeAmount <int> 10000000, 630000, 10000000, 1150000, 1…
$ nobelPrizes_prizeAmountAdjusted <int> 15547541, 4304697, 14874529, 3923237, …
$ nobelPrizes_affiliations <list> [<data.frame[1 x 8]>], [<data.frame[1 …
$ nobelPrizes_links <list> [<data.frame[3 x 6]>], [<data.frame[3 …
$ nobelPrizes_residences <list> <NULL>, <NULL>, <NULL>, <NULL>, <NU…
prizes_flat <- prizes |>
as.data.frame() |>
flatten()
names(prizes_flat) [1] "id" "gender"
[3] "nobelPrizes_awardYear" "nobelPrizes_sortOrder"
[5] "nobelPrizes_portion" "nobelPrizes_dateAwarded"
[7] "nobelPrizes_prizeStatus" "nobelPrizes_prizeAmount"
[9] "nobelPrizes_prizeAmountAdjusted" "nobelPrizes_affiliations"
[11] "nobelPrizes_links" "nobelPrizes_residences"
[13] "fullName.en" "fullName.se"
[15] "birth.date" "birth.year"
[17] "birth.place.city.en" "birth.place.city.no"
[19] "birth.place.city.se" "birth.place.country.en"
[21] "birth.place.country.no" "birth.place.country.se"
[23] "birth.place.cityNow.en" "birth.place.cityNow.no"
[25] "birth.place.cityNow.se" "birth.place.cityNow.sameAs"
[27] "birth.place.cityNow.latitude" "birth.place.cityNow.longitude"
[29] "birth.place.countryNow.en" "birth.place.countryNow.no"
[31] "birth.place.countryNow.se" "birth.place.countryNow.sameAs"
[33] "birth.place.countryNow.latitude" "birth.place.countryNow.longitude"
[35] "birth.place.continent.en" "birth.place.continent.no"
[37] "birth.place.continent.se" "birth.place.locationString.en"
[39] "birth.place.locationString.no" "birth.place.locationString.se"
[41] "nobelPrizes_category.en" "nobelPrizes_category.no"
[43] "nobelPrizes_category.se" "nobelPrizes_categoryFullName.en"
[45] "nobelPrizes_categoryFullName.no" "nobelPrizes_categoryFullName.se"
[47] "nobelPrizes_motivation.en" "nobelPrizes_motivation.se"
[49] "nobelPrizes_motivation.no"
head(prizes_flat, 3)| id | gender | nobelPrizes_awardYear | nobelPrizes_sortOrder | nobelPrizes_portion | nobelPrizes_dateAwarded | nobelPrizes_prizeStatus | nobelPrizes_prizeAmount | nobelPrizes_prizeAmountAdjusted | nobelPrizes_affiliations | nobelPrizes_links | nobelPrizes_residences | fullName.en | fullName.se | birth.date | birth.year | birth.place.city.en | birth.place.city.no | birth.place.city.se | birth.place.country.en | birth.place.country.no | birth.place.country.se | birth.place.cityNow.en | birth.place.cityNow.no | birth.place.cityNow.se | birth.place.cityNow.sameAs | birth.place.cityNow.latitude | birth.place.cityNow.longitude | birth.place.countryNow.en | birth.place.countryNow.no | birth.place.countryNow.se | birth.place.countryNow.sameAs | birth.place.countryNow.latitude | birth.place.countryNow.longitude | birth.place.continent.en | birth.place.continent.no | birth.place.continent.se | birth.place.locationString.en | birth.place.locationString.no | birth.place.locationString.se | nobelPrizes_category.en | nobelPrizes_category.no | nobelPrizes_category.se | nobelPrizes_categoryFullName.en | nobelPrizes_categoryFullName.no | nobelPrizes_categoryFullName.se | nobelPrizes_motivation.en | nobelPrizes_motivation.se | nobelPrizes_motivation.no |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 745 | male | 2001 | 2 | 1/3 | 2001-10-10 | received | 1.0e+07 | 15547541 | Stanford University , Stanford University , Stanford University , Stanford University , Stanford, CA , Stanford, CA , Stanford, CA , USA , USA , USA , Stanford, CA , Stanford, CA , Stanford, CA , https://www.wikidata.org/wiki/Q173813 , https://www.wikipedia.org/wiki/Stanford,_California, 37.424734 , -122.163858 , USA , USA , USA , https://www.wikidata.org/wiki/Q30 , 39.828175 , -98.579500 , North America , Stanford, CA, USA , Stanford, CA, USA , Stanford, CA, USA | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/eco/2001 , https://www.nobelprize.org/prizes/economic-sciences/2001/spence/facts/ , https://www.nobelprize.org/prizes/economic-sciences/2001/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , A. Michael Spence - Facts , The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel 2001, laureate facts , prize summary | NULL | A. Michael Spence | A. Michael Spence | 1943-11-07 | 1943 | Montclair, NJ | Montclair, NJ | Montclair, NJ | USA | USA | USA | Montclair, NJ | Montclair, NJ | Montclair, NJ | https://www.wikidata.org/wiki/Q678437 , https://www.wikipedia.org/wiki/Montclair,_New_Jersey | 40.825930 | -74.209030 | USA | USA | USA | https://www.wikidata.org/wiki/Q30 | 39.828175 | -98.579500 | North America | Nord-Amerika | Nordamerika | Montclair, NJ, USA | Montclair, NJ, USA | Montclair, NJ, USA | Economic Sciences | Økonomi | Ekonomi | The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel | Sveriges Riksbanks pris i økonomisk vitenskap til minne om Alfred Nobel | Sveriges Riksbanks pris i ekonomisk vetenskap till Alfred Nobels minne | for their analyses of markets with asymmetric information | för deras analys av marknader med assymetrisk informations | NA |
| 102 | male | 1975 | 1 | 1/3 | 1975-10-17 | received | 6.3e+05 | 4304697 | Niels Bohr Institute , Niels Bohr Institute , Niels Bohr Institute , Niels Bohr Institute , Copenhagen , København , Köpenhamn , Denmark , Danmark , Danmark , Copenhagen , København , Köpenhamn , https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen, 55.678127 , 12.572532 , Denmark , Danmark , Danmark , https://www.wikidata.org/wiki/Q35 , 56.000000 , 10.000000 , Europe , Copenhagen, Denmark , København, Danmark , Köpenhamn, Danmark | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/phy/1975 , https://www.nobelprize.org/prizes/physics/1975/bohr/facts/, https://www.nobelprize.org/prizes/physics/1975/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aage N. Bohr - Facts , The Nobel Prize in Physics 1975 , laureate facts , prize summary | NULL | Aage Niels Bohr | Aage Niels Bohr | 1922-06-19 | 1922 | Copenhagen | København | Köpenhamn | Denmark | Danmark | Danmark | Copenhagen | København | Köpenhamn | https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen | 55.678127 | 12.572532 | Denmark | Danmark | Danmark | https://www.wikidata.org/wiki/Q35 | 56.000000 | 10.000000 | Europe | Europa | Europa | Copenhagen, Denmark | København, Danmark | Köpenhamn, Danmark | Physics | Fysikk | Fysik | The Nobel Prize in Physics | Nobelprisen i fysikk | Nobelpriset i fysik | for the discovery of the connection between collective motion and particle motion in atomic nuclei and the development of the theory of the structure of the atomic nucleus based on this connection | för upptäckten av sambandet mellan kollektiva rörelser och partikelrörelser i atomkärnor, samt den därpå baserade utvecklingen av teorien för atomkärnans struktur | NA |
| 779 | male | 2004 | 1 | 1/3 | 2004-10-06 | received | 1.0e+07 | 14874529 | Technion - Israel Institute of Technology, Technion - Israel Institute of Technology, Technion - Israel Institute of Technology, Technion - Israel Institute of Technology, Haifa , Haifa , Haifa , Israel , Israel , Israel , Haifa , Haifa , Haifa , https://www.wikidata.org/wiki/Q41621 , https://www.wikipedia.org/wiki/Haifa , 32.794421 , 34.990340 , Israel , Israel , Israel , https://www.wikidata.org/wiki/Q801 , 31.000000 , 35.000000 , Asia , Haifa, Israel , Haifa, Israel , Haifa, Israel | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/che/2004 , https://www.nobelprize.org/prizes/chemistry/2004/ciechanover/facts/, https://www.nobelprize.org/prizes/chemistry/2004/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aaron Ciechanover - Facts , The Nobel Prize in Chemistry 2004 , laureate facts , prize summary | NULL | Aaron Ciechanover | Aaron Ciechanover | 1947-10-01 | 1947 | Haifa | Haifa | Haifa | British Protectorate of Palestine | British i Palestina | British Protectorate of Palestine | Haifa | Haifa | Haifa | https://www.wikidata.org/wiki/Q41621, https://www.wikipedia.org/wiki/Haifa | 32.794421 | 34.990340 | Israel | Israel | Israel | https://www.wikidata.org/wiki/Q801 | 31.000000 | 35.000000 | Asia | Asia | Asien | Haifa, British Protectorate of Palestine (now Israel) | Haifa, British i Palestina (nå Israel) | Haifa, British Protectorate of Palestine (nu Israel) | Chemistry | Kjemi | Kemi | The Nobel Prize in Chemistry | Nobelprisen i kjemi | Nobelpriset i kemi | for the discovery of ubiquitin-mediated protein degradation | för upptäckten av ubiquitinmedierad proteinnedbrytning | NA |
As we can see we have unflattened the nobelPrizes data so now we can see what else is being stored in it more clearly.
As a precaution, we will further unnest the data if needed.
prizes_aff <- prizes_flat |>
as_tibble() |>
unnest(nobelPrizes_affiliations, keep_empty = TRUE, names_sep = "_") |>
as.data.frame() |>
jsonlite::flatten() |>
as_tibble()
glimpse(prizes_aff)Rows: 30
Columns: 74
$ id <chr> "745", "102", "779", "25…
$ gender <chr> "male", "male", "male", …
$ nobelPrizes_awardYear <chr> "2001", "1975", "2004", …
$ nobelPrizes_sortOrder <chr> "2", "1", "1", "1", "1",…
$ nobelPrizes_portion <chr> "1/3", "1/3", "1/3", "1"…
$ nobelPrizes_dateAwarded <chr> "2001-10-10", "1975-10-1…
$ nobelPrizes_prizeStatus <chr> "received", "received", …
$ nobelPrizes_prizeAmount <int> 10000000, 630000, 100000…
$ nobelPrizes_prizeAmountAdjusted <int> 15547541, 4304697, 14874…
$ nobelPrizes_links <list> [<data.frame[3 x 6]>], …
$ nobelPrizes_residences <list> <NULL>, <NULL>, <NULL>,…
$ fullName.en <chr> "A. Michael Spence", "Aa…
$ fullName.se <chr> "A. Michael Spence", "Aa…
$ birth.date <chr> "1943-11-07", "1922-06-1…
$ birth.year <chr> "1943", "1922", "1947", …
$ birth.place.city.en <chr> "Montclair, NJ", "Copenh…
$ birth.place.city.no <chr> "Montclair, NJ", "Københ…
$ birth.place.city.se <chr> "Montclair, NJ", "Köpenh…
$ birth.place.country.en <chr> "USA", "Denmark", "Briti…
$ birth.place.country.no <chr> "USA", "Danmark", "Briti…
$ birth.place.country.se <chr> "USA", "Danmark", "Briti…
$ birth.place.cityNow.en <chr> "Montclair, NJ", "Copenh…
$ birth.place.cityNow.no <chr> "Montclair, NJ", "Københ…
$ birth.place.cityNow.se <chr> "Montclair, NJ", "Köpenh…
$ birth.place.cityNow.sameAs <list> <"https://www.wikidata.…
$ birth.place.cityNow.latitude <chr> "40.825930", "55.678127"…
$ birth.place.cityNow.longitude <chr> "-74.209030", "12.572532…
$ birth.place.countryNow.en <chr> "USA", "Denmark", "Israe…
$ birth.place.countryNow.no <chr> "USA", "Danmark", "Israe…
$ birth.place.countryNow.se <chr> "USA", "Danmark", "Israe…
$ birth.place.countryNow.sameAs <list> "https://www.wikidata.o…
$ birth.place.countryNow.latitude <chr> "39.828175", "56.000000"…
$ birth.place.countryNow.longitude <chr> "-98.579500", "10.000000…
$ birth.place.continent.en <chr> "North America", "Europe…
$ birth.place.continent.no <chr> "Nord-Amerika", "Europa"…
$ birth.place.continent.se <chr> "Nordamerika", "Europa",…
$ birth.place.locationString.en <chr> "Montclair, NJ, USA", "C…
$ birth.place.locationString.no <chr> "Montclair, NJ, USA", "K…
$ birth.place.locationString.se <chr> "Montclair, NJ, USA", "K…
$ nobelPrizes_category.en <chr> "Economic Sciences", "Ph…
$ nobelPrizes_category.no <chr> "Økonomi", "Fysikk", "Kj…
$ nobelPrizes_category.se <chr> "Ekonomi", "Fysik", "Kem…
$ nobelPrizes_categoryFullName.en <chr> "The Sveriges Riksbank P…
$ nobelPrizes_categoryFullName.no <chr> "Sveriges Riksbanks pris…
$ nobelPrizes_categoryFullName.se <chr> "Sveriges Riksbanks pris…
$ nobelPrizes_motivation.en <chr> "for their analyses of m…
$ nobelPrizes_motivation.se <chr> "för deras analys av mar…
$ nobelPrizes_motivation.no <chr> NA, NA, NA, NA, NA, NA, …
$ nobelPrizes_affiliations_name.en <chr> "Stanford University", "…
$ nobelPrizes_affiliations_name.no <chr> "Stanford University", "…
$ nobelPrizes_affiliations_name.se <chr> "Stanford University", "…
$ nobelPrizes_affiliations_nameNow.en <chr> "Stanford University", "…
$ nobelPrizes_affiliations_city.en <chr> "Stanford, CA", "Copenha…
$ nobelPrizes_affiliations_city.no <chr> "Stanford, CA", "Københa…
$ nobelPrizes_affiliations_city.se <chr> "Stanford, CA", "Köpenha…
$ nobelPrizes_affiliations_country.en <chr> "USA", "Denmark", "Israe…
$ nobelPrizes_affiliations_country.no <chr> "USA", "Danmark", "Israe…
$ nobelPrizes_affiliations_country.se <chr> "USA", "Danmark", "Israe…
$ nobelPrizes_affiliations_cityNow.en <chr> "Stanford, CA", "Copenha…
$ nobelPrizes_affiliations_cityNow.no <chr> "Stanford, CA", "Københa…
$ nobelPrizes_affiliations_cityNow.se <chr> "Stanford, CA", "Köpenha…
$ nobelPrizes_affiliations_cityNow.sameAs <list> <"https://www.wikidata.…
$ nobelPrizes_affiliations_cityNow.latitude <chr> "37.424734", "55.678127"…
$ nobelPrizes_affiliations_cityNow.longitude <chr> "-122.163858", "12.57253…
$ nobelPrizes_affiliations_countryNow.en <chr> "USA", "Denmark", "Israe…
$ nobelPrizes_affiliations_countryNow.no <chr> "USA", "Danmark", "Israe…
$ nobelPrizes_affiliations_countryNow.se <chr> "USA", "Danmark", "Israe…
$ nobelPrizes_affiliations_countryNow.sameAs <list> "https://www.wikidata.o…
$ nobelPrizes_affiliations_countryNow.latitude <chr> "39.828175", "56.000000"…
$ nobelPrizes_affiliations_countryNow.longitude <chr> "-98.579500", "10.000000…
$ nobelPrizes_affiliations_continent.en <chr> "North America", "Europe…
$ nobelPrizes_affiliations_locationString.en <chr> "Stanford, CA, USA", "Co…
$ nobelPrizes_affiliations_locationString.no <chr> "Stanford, CA, USA", "Kø…
$ nobelPrizes_affiliations_locationString.se <chr> "Stanford, CA, USA", "Kö…
head(prizes_aff)| id | gender | nobelPrizes_awardYear | nobelPrizes_sortOrder | nobelPrizes_portion | nobelPrizes_dateAwarded | nobelPrizes_prizeStatus | nobelPrizes_prizeAmount | nobelPrizes_prizeAmountAdjusted | nobelPrizes_links | nobelPrizes_residences | fullName.en | fullName.se | birth.date | birth.year | birth.place.city.en | birth.place.city.no | birth.place.city.se | birth.place.country.en | birth.place.country.no | birth.place.country.se | birth.place.cityNow.en | birth.place.cityNow.no | birth.place.cityNow.se | birth.place.cityNow.sameAs | birth.place.cityNow.latitude | birth.place.cityNow.longitude | birth.place.countryNow.en | birth.place.countryNow.no | birth.place.countryNow.se | birth.place.countryNow.sameAs | birth.place.countryNow.latitude | birth.place.countryNow.longitude | birth.place.continent.en | birth.place.continent.no | birth.place.continent.se | birth.place.locationString.en | birth.place.locationString.no | birth.place.locationString.se | nobelPrizes_category.en | nobelPrizes_category.no | nobelPrizes_category.se | nobelPrizes_categoryFullName.en | nobelPrizes_categoryFullName.no | nobelPrizes_categoryFullName.se | nobelPrizes_motivation.en | nobelPrizes_motivation.se | nobelPrizes_motivation.no | nobelPrizes_affiliations_name.en | nobelPrizes_affiliations_name.no | nobelPrizes_affiliations_name.se | nobelPrizes_affiliations_nameNow.en | nobelPrizes_affiliations_city.en | nobelPrizes_affiliations_city.no | nobelPrizes_affiliations_city.se | nobelPrizes_affiliations_country.en | nobelPrizes_affiliations_country.no | nobelPrizes_affiliations_country.se | nobelPrizes_affiliations_cityNow.en | nobelPrizes_affiliations_cityNow.no | nobelPrizes_affiliations_cityNow.se | nobelPrizes_affiliations_cityNow.sameAs | nobelPrizes_affiliations_cityNow.latitude | nobelPrizes_affiliations_cityNow.longitude | nobelPrizes_affiliations_countryNow.en | nobelPrizes_affiliations_countryNow.no | nobelPrizes_affiliations_countryNow.se | nobelPrizes_affiliations_countryNow.sameAs | nobelPrizes_affiliations_countryNow.latitude | nobelPrizes_affiliations_countryNow.longitude | nobelPrizes_affiliations_continent.en | nobelPrizes_affiliations_locationString.en | nobelPrizes_affiliations_locationString.no | nobelPrizes_affiliations_locationString.se |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 745 | male | 2001 | 2 | 1/3 | 2001-10-10 | received | 10000000 | 15547541 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/eco/2001 , https://www.nobelprize.org/prizes/economic-sciences/2001/spence/facts/ , https://www.nobelprize.org/prizes/economic-sciences/2001/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , A. Michael Spence - Facts , The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel 2001, laureate facts , prize summary | NULL | A. Michael Spence | A. Michael Spence | 1943-11-07 | 1943 | Montclair, NJ | Montclair, NJ | Montclair, NJ | USA | USA | USA | Montclair, NJ | Montclair, NJ | Montclair, NJ | https://www.wikidata.org/wiki/Q678437 , https://www.wikipedia.org/wiki/Montclair,_New_Jersey | 40.825930 | -74.209030 | USA | USA | USA | https://www.wikidata.org/wiki/Q30 | 39.828175 | -98.579500 | North America | Nord-Amerika | Nordamerika | Montclair, NJ, USA | Montclair, NJ, USA | Montclair, NJ, USA | Economic Sciences | Økonomi | Ekonomi | The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel | Sveriges Riksbanks pris i økonomisk vitenskap til minne om Alfred Nobel | Sveriges Riksbanks pris i ekonomisk vetenskap till Alfred Nobels minne | for their analyses of markets with asymmetric information | för deras analys av marknader med assymetrisk informations | NA | Stanford University | Stanford University | Stanford University | Stanford University | Stanford, CA | Stanford, CA | Stanford, CA | USA | USA | USA | Stanford, CA | Stanford, CA | Stanford, CA | https://www.wikidata.org/wiki/Q173813 , https://www.wikipedia.org/wiki/Stanford,_California | 37.424734 | -122.163858 | USA | USA | USA | https://www.wikidata.org/wiki/Q30 | 39.828175 | -98.579500 | North America | Stanford, CA, USA | Stanford, CA, USA | Stanford, CA, USA |
| 102 | male | 1975 | 1 | 1/3 | 1975-10-17 | received | 630000 | 4304697 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/phy/1975 , https://www.nobelprize.org/prizes/physics/1975/bohr/facts/, https://www.nobelprize.org/prizes/physics/1975/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aage N. Bohr - Facts , The Nobel Prize in Physics 1975 , laureate facts , prize summary | NULL | Aage Niels Bohr | Aage Niels Bohr | 1922-06-19 | 1922 | Copenhagen | København | Köpenhamn | Denmark | Danmark | Danmark | Copenhagen | København | Köpenhamn | https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen | 55.678127 | 12.572532 | Denmark | Danmark | Danmark | https://www.wikidata.org/wiki/Q35 | 56.000000 | 10.000000 | Europe | Europa | Europa | Copenhagen, Denmark | København, Danmark | Köpenhamn, Danmark | Physics | Fysikk | Fysik | The Nobel Prize in Physics | Nobelprisen i fysikk | Nobelpriset i fysik | for the discovery of the connection between collective motion and particle motion in atomic nuclei and the development of the theory of the structure of the atomic nucleus based on this connection | för upptäckten av sambandet mellan kollektiva rörelser och partikelrörelser i atomkärnor, samt den därpå baserade utvecklingen av teorien för atomkärnans struktur | NA | Niels Bohr Institute | Niels Bohr Institute | Niels Bohr Institute | Niels Bohr Institute | Copenhagen | København | Köpenhamn | Denmark | Danmark | Danmark | Copenhagen | København | Köpenhamn | https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen | 55.678127 | 12.572532 | Denmark | Danmark | Danmark | https://www.wikidata.org/wiki/Q35 | 56.000000 | 10.000000 | Europe | Copenhagen, Denmark | København, Danmark | Köpenhamn, Danmark |
| 779 | male | 2004 | 1 | 1/3 | 2004-10-06 | received | 10000000 | 14874529 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/che/2004 , https://www.nobelprize.org/prizes/chemistry/2004/ciechanover/facts/, https://www.nobelprize.org/prizes/chemistry/2004/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aaron Ciechanover - Facts , The Nobel Prize in Chemistry 2004 , laureate facts , prize summary | NULL | Aaron Ciechanover | Aaron Ciechanover | 1947-10-01 | 1947 | Haifa | Haifa | Haifa | British Protectorate of Palestine | British i Palestina | British Protectorate of Palestine | Haifa | Haifa | Haifa | https://www.wikidata.org/wiki/Q41621, https://www.wikipedia.org/wiki/Haifa | 32.794421 | 34.990340 | Israel | Israel | Israel | https://www.wikidata.org/wiki/Q801 | 31.000000 | 35.000000 | Asia | Asia | Asien | Haifa, British Protectorate of Palestine (now Israel) | Haifa, British i Palestina (nå Israel) | Haifa, British Protectorate of Palestine (nu Israel) | Chemistry | Kjemi | Kemi | The Nobel Prize in Chemistry | Nobelprisen i kjemi | Nobelpriset i kemi | for the discovery of ubiquitin-mediated protein degradation | för upptäckten av ubiquitinmedierad proteinnedbrytning | NA | Technion - Israel Institute of Technology | Technion - Israel Institute of Technology | Technion - Israel Institute of Technology | Technion - Israel Institute of Technology | Haifa | Haifa | Haifa | Israel | Israel | Israel | Haifa | Haifa | Haifa | https://www.wikidata.org/wiki/Q41621, https://www.wikipedia.org/wiki/Haifa | 32.794421 | 34.990340 | Israel | Israel | Israel | https://www.wikidata.org/wiki/Q801 | 31.000000 | 35.000000 | Asia | Haifa, Israel | Haifa, Israel | Haifa, Israel |
| 259 | male | 1982 | 1 | 1 | 1982-10-18 | received | 1150000 | 3923237 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/che/1982 , https://www.nobelprize.org/prizes/chemistry/1982/klug/facts/, https://www.nobelprize.org/prizes/chemistry/1982/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aaron Klug - Facts , The Nobel Prize in Chemistry 1982 , laureate facts , prize summary | NULL | Aaron Klug | Aaron Klug | 1926-08-11 | 1926 | Zelvas | Zelvas | Zelvas | Lithuania | Litauen | Litauen | Zelvas | Zelvas | Zelvas | https://www.wikidata.org/wiki/Q691679 , https://www.wikipedia.org/wiki/%C5%BDelva | 53.148256 | 24.816515 | Lithuania | Litauen | Litauen | https://www.wikidata.org/wiki/Q37 | 55.200000 | 24.000000 | Europe | Europa | Europa | Zelvas, Lithuania | Zelvas, Litauen | Zelvas, Litauen | Chemistry | Kjemi | Kemi | The Nobel Prize in Chemistry | Nobelprisen i kjemi | Nobelpriset i kemi | for his development of crystallographic electron microscopy and his structural elucidation of biologically important nucleic acid-protein complexes | för hans utveckling av kristallografisk elektronmikroskopi och hans klarläggande av strukturen hos biologiskt viktiga nukleinsyra-proteinkomplex | NA | MRC Laboratory of Molecular Biology | MRC Laboratory of Molecular Biology | MRC Laboratory of Molecular Biology | MRC Laboratory of Molecular Biology | Cambridge | Cambridge | Cambridge | United Kingdom | Storbritannia | Storbritannien | Cambridge | Cambridge | Cambridge | https://www.wikidata.org/wiki/Q350 , https://www.wikipedia.org/wiki/Cambridge | 52.194605 | 0.135092 | United Kingdom | Storbritannia | Storbritannien | https://www.wikidata.org/wiki/Q145 | 54.600000 | -2.000000 | Europe | Cambridge, United Kingdom | Cambridge, Storbritannia | Cambridge, Storbritannien |
| 1004 | male | 2021 | 1 | 1 | 2021-10-07 | received | 10000000 | 12096939 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/lit/2021 , https://www.nobelprize.org/prizes/literature/2021/gurnah/facts/, https://www.nobelprize.org/prizes/literature/2021/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Abdulrazak Gurnah - Facts , The Nobel Prize in Literature 2021 , laureate facts , prize summary | NULL | Abdulrazak Gurnah | Abdulrazak Gurnah | 1948-00-00 | 1948 | NA | NA | NA | NA | NA | NA | NA | NA | NA | NULL | NA | NA | NA | NA | NA | NULL | NA | NA | NA | NA | NA | NA | NA | NA | Literature | Litteratur | Litteratur | The Nobel Prize in Literature | Nobelprisen i litteratur | Nobelpriset i litteratur | for his uncompromising and compassionate penetration of the effects of colonialism and the fate of the refugee in the gulf between cultures and continents | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NULL | NA | NA | NA | NA | NA | NULL | NA | NA | NA | NA | NA | NA |
| 114 | male | 1979 | 2 | 1/3 | 1979-10-15 | received | 800000 | 3778486 | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/phy/1979 , https://www.nobelprize.org/prizes/physics/1979/salam/facts/, https://www.nobelprize.org/prizes/physics/1979/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Abdus Salam - Facts , The Nobel Prize in Physics 1979 , laureate facts , prize summary | NULL | Abdus Salam | Abdus Salam | 1926-01-29 | 1926 | Jhang Maghiāna | Jhang Maghiāna | Jhang Maghiāna | India | India | Indien | Jhang Maghiāna | Jhang Maghiāna | Jhang Maghiāna | https://www.wikidata.org/wiki/Q1026616, https://www.wikipedia.org/wiki/Jhang | 31.268056 | 72.318056 | Pakistan | Pakistan | Pakistan | https://www.wikidata.org/wiki/Q843 | 30.000000 | 71.000000 | Asia | Asia | Asien | Jhang Maghiāna, India (now Pakistan) | Jhang Maghiāna, India (nå Pakistan) | Jhang Maghiāna, Indien (nu Pakistan) | Physics | Fysikk | Fysik | The Nobel Prize in Physics | Nobelprisen i fysikk | Nobelpriset i fysik | for their contributions to the theory of the unified weak and electromagnetic interaction between elementary particles, including, inter alia, the prediction of the weak neutral current | för deras insatser inom teorin för förenad svag och elektromagnetisk växelverkan mellan elementar partiklar, innefattande bl.a. förutsägelsen av den svaga neutrala strömmen | NA | International Centre for Theoretical Physics | International Centre for Theoretical Physics | International Centre for Theoretical Physics | International Centre for Theoretical Physics | Trieste | Trieste | Trieste | Italy | Italia | Italien | Trieste | Trieste | Trieste | https://www.wikidata.org/wiki/Q546 , https://www.wikipedia.org/wiki/Trieste | 45.649433 | 13.776623 | Italy | Italia | Italien | https://www.wikidata.org/wiki/Q38 | 42.500000 | 12.500000 | Europe | Trieste, Italy | Trieste, Italia | Trieste, Italien |
Now we have a data table with clear information of the columns and what we want to extract. Given that this is not the full list of the API data, we will need to start requesting for the full list without abusing the server request.
nobel_prize_JSON$meta$offset[1] 0
nobel_prize_JSON$meta$limit[1] 25
nobel_prize_JSON$meta$count[1] 1028
# limit of 25
# Offset of 0, meaning the list starts at that very first item
# count of 1028, the total number of items in the datasettotal <- nobel_prize_JSON$meta$count
offsets <- seq(0, total, by = 100) # loop over the offset by 100
pages <- map(offsets, \(off) {
request("https://api.nobelprize.org/2.1/laureates") |>
req_url_query(limit = 100, offset = off) |>
req_perform() |>
resp_body_json(simplifyVector = TRUE)
})
laureates <- map(pages, "laureates") |> bind_rows()
nrow(laureates)[1] 1028
laureates is our full data that we extracted from the API, now we need to create the table and overwrite our existing prize_aff.
prizes_aff <- laureates |>
select(id, fullName, gender, birth, nobelPrizes) |>
unnest(nobelPrizes, names_sep = "_") |>
as.data.frame() |>
jsonlite::flatten() |>
as_tibble() |>
unnest(nobelPrizes_affiliations, keep_empty = TRUE, names_sep = "_") |>
as.data.frame() |>
jsonlite::flatten() |>
as_tibble()
nrow(prizes_aff)[1] 1126
head(prizes_aff, 2)| id | gender | nobelPrizes_awardYear | nobelPrizes_sortOrder | nobelPrizes_portion | nobelPrizes_dateAwarded | nobelPrizes_prizeStatus | nobelPrizes_prizeAmount | nobelPrizes_prizeAmountAdjusted | nobelPrizes_affiliations_nativeName | nobelPrizes_links | nobelPrizes_residences | fullName.en | fullName.se | fullName.no | birth.date | birth.year | birth.place.city.en | birth.place.city.no | birth.place.city.se | birth.place.country.en | birth.place.country.no | birth.place.country.se | birth.place.cityNow.en | birth.place.cityNow.no | birth.place.cityNow.se | birth.place.cityNow.sameAs | birth.place.cityNow.latitude | birth.place.cityNow.longitude | birth.place.countryNow.en | birth.place.countryNow.no | birth.place.countryNow.se | birth.place.countryNow.sameAs | birth.place.countryNow.latitude | birth.place.countryNow.longitude | birth.place.continent.en | birth.place.continent.no | birth.place.continent.se | birth.place.locationString.en | birth.place.locationString.no | birth.place.locationString.se | nobelPrizes_category.en | nobelPrizes_category.no | nobelPrizes_category.se | nobelPrizes_categoryFullName.en | nobelPrizes_categoryFullName.no | nobelPrizes_categoryFullName.se | nobelPrizes_motivation.en | nobelPrizes_motivation.se | nobelPrizes_motivation.no | nobelPrizes_topMotivation.en | nobelPrizes_topMotivation.se | nobelPrizes_affiliations_name.en | nobelPrizes_affiliations_name.no | nobelPrizes_affiliations_name.se | nobelPrizes_affiliations_nameNow.en | nobelPrizes_affiliations_city.en | nobelPrizes_affiliations_city.no | nobelPrizes_affiliations_city.se | nobelPrizes_affiliations_country.en | nobelPrizes_affiliations_country.no | nobelPrizes_affiliations_country.se | nobelPrizes_affiliations_cityNow.en | nobelPrizes_affiliations_cityNow.no | nobelPrizes_affiliations_cityNow.se | nobelPrizes_affiliations_cityNow.sameAs | nobelPrizes_affiliations_cityNow.latitude | nobelPrizes_affiliations_cityNow.longitude | nobelPrizes_affiliations_countryNow.en | nobelPrizes_affiliations_countryNow.no | nobelPrizes_affiliations_countryNow.se | nobelPrizes_affiliations_countryNow.sameAs | nobelPrizes_affiliations_countryNow.latitude | nobelPrizes_affiliations_countryNow.longitude | nobelPrizes_affiliations_continent.en | nobelPrizes_affiliations_locationString.en | nobelPrizes_affiliations_locationString.no | nobelPrizes_affiliations_locationString.se |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 745 | male | 2001 | 2 | 1/3 | 2001-10-10 | received | 1.0e+07 | 15547541 | NA | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/eco/2001 , https://www.nobelprize.org/prizes/economic-sciences/2001/spence/facts/ , https://www.nobelprize.org/prizes/economic-sciences/2001/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , A. Michael Spence - Facts , The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel 2001, laureate facts , prize summary | NULL | A. Michael Spence | A. Michael Spence | NA | 1943-11-07 | 1943 | Montclair, NJ | Montclair, NJ | Montclair, NJ | USA | USA | USA | Montclair, NJ | Montclair, NJ | Montclair, NJ | https://www.wikidata.org/wiki/Q678437 , https://www.wikipedia.org/wiki/Montclair,_New_Jersey | 40.825930 | -74.209030 | USA | USA | USA | https://www.wikidata.org/wiki/Q30 | 39.828175 | -98.579500 | North America | Nord-Amerika | Nordamerika | Montclair, NJ, USA | Montclair, NJ, USA | Montclair, NJ, USA | Economic Sciences | Økonomi | Ekonomi | The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel | Sveriges Riksbanks pris i økonomisk vitenskap til minne om Alfred Nobel | Sveriges Riksbanks pris i ekonomisk vetenskap till Alfred Nobels minne | for their analyses of markets with asymmetric information | för deras analys av marknader med assymetrisk informations | NA | NA | NA | Stanford University | Stanford University | Stanford University | Stanford University | Stanford, CA | Stanford, CA | Stanford, CA | USA | USA | USA | Stanford, CA | Stanford, CA | Stanford, CA | https://www.wikidata.org/wiki/Q173813 , https://www.wikipedia.org/wiki/Stanford,_California | 37.424734 | -122.163858 | USA | USA | USA | https://www.wikidata.org/wiki/Q30 | 39.828175 | -98.579500 | North America | Stanford, CA, USA | Stanford, CA, USA | Stanford, CA, USA |
| 102 | male | 1975 | 1 | 1/3 | 1975-10-17 | received | 6.3e+05 | 4304697 | NA | nobelPrize , external , external , https://api.nobelprize.org/2/nobelPrize/phy/1975 , https://www.nobelprize.org/prizes/physics/1975/bohr/facts/, https://www.nobelprize.org/prizes/physics/1975/summary/ , GET , GET , GET , application/json , text/html , text/html , NA , Aage N. Bohr - Facts , The Nobel Prize in Physics 1975 , laureate facts , prize summary | NULL | Aage Niels Bohr | Aage Niels Bohr | NA | 1922-06-19 | 1922 | Copenhagen | København | Köpenhamn | Denmark | Danmark | Danmark | Copenhagen | København | Köpenhamn | https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen | 55.678127 | 12.572532 | Denmark | Danmark | Danmark | https://www.wikidata.org/wiki/Q35 | 56.000000 | 10.000000 | Europe | Europa | Europa | Copenhagen, Denmark | København, Danmark | Köpenhamn, Danmark | Physics | Fysikk | Fysik | The Nobel Prize in Physics | Nobelprisen i fysikk | Nobelpriset i fysik | for the discovery of the connection between collective motion and particle motion in atomic nuclei and the development of the theory of the structure of the atomic nucleus based on this connection | för upptäckten av sambandet mellan kollektiva rörelser och partikelrörelser i atomkärnor, samt den därpå baserade utvecklingen av teorien för atomkärnans struktur | NA | NA | NA | Niels Bohr Institute | Niels Bohr Institute | Niels Bohr Institute | Niels Bohr Institute | Copenhagen | København | Köpenhamn | Denmark | Danmark | Danmark | Copenhagen | København | Köpenhamn | https://www.wikidata.org/wiki/Q1748 , https://www.wikipedia.org/wiki/Copenhagen | 55.678127 | 12.572532 | Denmark | Danmark | Danmark | https://www.wikidata.org/wiki/Q35 | 56.000000 | 10.000000 | Europe | Copenhagen, Denmark | København, Danmark | Köpenhamn, Danmark |
nobel_table <- prizes_aff |>
select(id,
gender,
birth_year = birth.year,
full_name = fullName.en,
award_year = nobelPrizes_awardYear,
prize_amt = nobelPrizes_prizeAmount,
birth_country = birth.place.country.en,
birth_continent = birth.place.continent.en,
prize_category = nobelPrizes_category.en
) |>
mutate(
birth_year = as.integer(birth_year),
award_year = as.integer(award_year)
)
glimpse(nobel_table)Rows: 1,126
Columns: 9
$ id <chr> "745", "102", "779", "259", "1004", "114", "114", "982…
$ gender <chr> "male", "male", "male", "male", "male", "male", "male"…
$ birth_year <int> 1943, 1922, 1947, 1926, 1948, 1926, 1926, 1961, 1976, …
$ full_name <chr> "A. Michael Spence", "Aage Niels Bohr", "Aaron Ciechan…
$ award_year <int> 2001, 1975, 2004, 1982, 2021, 1979, 1979, 2019, 2019, …
$ prize_amt <int> 10000000, 630000, 10000000, 1150000, 10000000, 800000,…
$ birth_country <chr> "USA", "Denmark", "British Protectorate of Palestine",…
$ birth_continent <chr> "North America", "Europe", "Asia", "Europe", NA, "Asia…
$ prize_category <chr> "Economic Sciences", "Physics", "Chemistry", "Chemistr…
head(nobel_table, 3)| id | gender | birth_year | full_name | award_year | prize_amt | birth_country | birth_continent | prize_category |
|---|---|---|---|---|---|---|---|---|
| 745 | male | 1943 | A. Michael Spence | 2001 | 1.0e+07 | USA | North America | Economic Sciences |
| 102 | male | 1922 | Aage Niels Bohr | 1975 | 6.3e+05 | Denmark | Europe | Physics |
| 779 | male | 1947 | Aaron Ciechanover | 2004 | 1.0e+07 | British Protectorate of Palestine | Asia | Chemistry |
nobel_prizes <- nobel_table |> distinct()
nrow(nobel_prizes) # There were duplicates[1] 1036
colSums(is.na(nobel_prizes)) id gender birth_year full_name award_year
0 31 31 31 0
prize_amt birth_country birth_continent prize_category
0 34 34 0
There are around 31-34 missing values, but we can filter it out easily when conducting analysis.
retrieved_at <- format(Sys.time(), tz = "UTC", usetz = TRUE)
matches_snapshot <- nobel_prizes |>
mutate(
retrieved_at = retrieved_at,
request_url = url,
.before = 1
)
head(matches_snapshot,3)| retrieved_at | request_url | id | gender | birth_year | full_name | award_year | prize_amt | birth_country | birth_continent | prize_category |
|---|---|---|---|---|---|---|---|---|---|---|
| 2026-11-05 18:16:31 UTC | https://api.nobelprize.org/2.1/laureates | 745 | male | 1943 | A. Michael Spence | 2001 | 1.0e+07 | USA | North America | Economic Sciences |
| 2026-11-05 18:16:31 UTC | https://api.nobelprize.org/2.1/laureates | 102 | male | 1922 | Aage Niels Bohr | 1975 | 6.3e+05 | Denmark | Europe | Physics |
| 2026-11-05 18:16:31 UTC | https://api.nobelprize.org/2.1/laureates | 779 | male | 1947 | Aaron Ciechanover | 2004 | 1.0e+07 | British Protectorate of Palestine | Asia | Chemistry |
We want to save this to a CSV file so we can do some offline work with this data.
write.csv(matches_snapshot, "nobel_table_data_api.csv", row.names = FALSE)data <- read.csv("https://raw.githubusercontent.com/HaiderrX/CUNY-SPS-MSDS/refs/heads/main/DATA607/Week%2010%20-%20Natural%20Language%20Processing/nobel_table_data_api.csv")# Creating a new dataframe where it drops the request information
clean_data <- data |>
select(-retrieved_at, -request_url)
glimpse(clean_data)Rows: 1,036
Columns: 9
$ id <int> 745, 102, 779, 259, 1004, 114, 982, 981, 843, 866, 199…
$ gender <chr> "male", "male", "male", "male", "male", "male", "male"…
$ birth_year <int> 1943, 1922, 1947, 1926, 1948, 1926, 1961, 1976, 1939, …
$ full_name <chr> "A. Michael Spence", "Aage Niels Bohr", "Aaron Ciechan…
$ award_year <int> 2001, 1975, 2004, 1982, 2021, 1979, 2019, 2019, 2009, …
$ prize_amt <int> 10000000, 630000, 10000000, 1150000, 10000000, 800000,…
$ birth_country <chr> "USA", "Denmark", "British Protectorate of Palestine",…
$ birth_continent <chr> "North America", "Europe", "Asia", "Europe", NA, "Asia…
$ prize_category <chr> "Economic Sciences", "Physics", "Chemistry", "Chemistr…
head(clean_data, 3)| id | gender | birth_year | full_name | award_year | prize_amt | birth_country | birth_continent | prize_category |
|---|---|---|---|---|---|---|---|---|
| 745 | male | 1943 | A. Michael Spence | 2001 | 1.0e+07 | USA | North America | Economic Sciences |
| 102 | male | 1922 | Aage Niels Bohr | 1975 | 6.3e+05 | Denmark | Europe | Physics |
| 779 | male | 1947 | Aaron Ciechanover | 2004 | 1.0e+07 | British Protectorate of Palestine | Asia | Chemistry |
| Variable | Definition |
|---|---|
id |
Laureate’s identifier number |
gender |
Laureate is either male or female |
birth_year |
Birth year of the laureate |
full_name |
Laureate’s full name |
award_year |
The year the laureate won the award |
prize_amt |
The amount of money laureate gained for the prize |
birth_country |
Laureate’s country of birth |
birth_continent |
Laureate’s continent of birth |
prize_category |
What field/subject the award belonged to |
For our analysis, we mentioned we want to ask 4 data-driven questions from this dataset.
Upon examining the subset of the data we collected, I would like to inquire the following:
Question 1: What is the top country that has won the most Nobel Prizes, and which gender has a higher proportion of that category?
Question 2: Per category, what is the average prize amount?
Question 3: Per country, are there more males or females winning the Nobel prize?
Question 4: Per category, what year had the most winners?
What categories have won the most Nobel prize, and if possible what is the percentage of the top country and gender that each category contains?
To answer this question, it may be easier to break it up to segments to build up our answer.
most_won_categories <- clean_data |>
count(prize_category, sort = TRUE, name = "total_wins") |>
mutate(pct_of_all_prizes = round((total_wins / sum(total_wins) * 100), 2))
most_won_categories| prize_category | total_wins | pct_of_all_prizes |
|---|---|---|
| Physiology or Medicine | 235 | 22.68 |
| Physics | 231 | 22.30 |
| Chemistry | 202 | 19.50 |
| Peace | 144 | 13.90 |
| Literature | 123 | 11.87 |
| Economic Sciences | 101 | 9.75 |
most_won_categories_country <- clean_data |>
filter(!is.na(birth_country)) |>
group_by(prize_category) |>
count(prize_category, birth_country, sort = TRUE, name = "total_wins") |>
group_by(birth_country) |>
mutate(pct_of_country = round((total_wins / sum(total_wins) * 100), 2))
most_won_categories_countrymost_won_categories_country_and_gender <- clean_data |>
filter(!is.na(birth_country), !is.na(gender)) |>
count(prize_category, birth_country, gender, name = "total_wins") |>
group_by(prize_category) |>
mutate(
category_total = sum(total_wins),
pct_of_category = round((total_wins / category_total) * 100, 2)
) |>
arrange(desc(total_wins))
most_won_categories_country_and_genderWith the initial build idea, we got 277 rows, so we could shorten to top country for each field and compare from there.
most_won_categories_country_and_gender <- clean_data |>
filter(!is.na(birth_country), !is.na(gender)) |>
count(prize_category, birth_country, gender, name = "total_wins") |>
group_by(prize_category) |>
mutate(
category_total = sum(total_wins),
pct_of_category = round((total_wins / category_total) * 100, 2)
) |>
top_n(1, total_wins) |>
arrange(desc(category_total))
most_won_categories_country_and_gender| prize_category | birth_country | gender | total_wins | category_total | pct_of_category |
|---|---|---|---|---|---|
| Physiology or Medicine | USA | male | 79 | 235 | 33.62 |
| Physics | USA | male | 71 | 230 | 30.87 |
| Chemistry | USA | male | 57 | 202 | 28.22 |
| Literature | France | male | 11 | 122 | 9.02 |
| Peace | USA | male | 16 | 113 | 14.16 |
| Economic Sciences | USA | male | 54 | 100 | 54.00 |
With our data, we can see almost all of the categories are won by people from the USA and Literature being won by France. The dominant gender is male for all of the categories.
In regard to our data with 277 rows, it was also a male dominant winner in the dataset. Similarly, the USA had the most winners in the categories listed above, but interestingly, the United Kingdom and Germany had he 2nd and 3rd most winners in every category except for Peace and Literature.
Per category, what is the average prize amount?
avg_prize_amt <- clean_data |>
group_by(prize_category) |>
summarize(
total_winner_counts = n(),
avg_prize = round(mean(prize_amt, na.rm=TRUE), 2)) |>
arrange(desc(avg_prize))
avg_prize_amt| prize_category | total_winner_counts | avg_prize |
|---|---|---|
| Economic Sciences | 101 | 6870208 |
| Chemistry | 202 | 4261324 |
| Physics | 231 | 3964896 |
| Peace | 144 | 3637040 |
| Physiology or Medicine | 235 | 3599919 |
| Literature | 123 | 2961643 |
Plot
With the provided table and plot, we can see that Economic Sciences laureates earn the most after being awarded a Nobel Prize, with Literature being the least.
ggplot(avg_prize_amt, aes(x = reorder(prize_category, total_winner_counts), y = total_winner_counts, fill = prize_category)) +
geom_col() +
coord_flip() +
labs(
title = "Winner Counts Per Category",
x = "Category",
y = "Counts",
fill = "Category"
) +
theme_minimal()Even though Economic Sciences laureates get more prize amounts, there are less winners versus a category like medicine or physics.
Per continent, are there more males or females winning the Nobel prize?
most_per_continent <- clean_data |>
filter(!is.na(birth_continent), !is.na(gender)) |>
count(birth_continent, gender, name = "total_wins") |>
group_by(birth_continent) |>
mutate(
continent_total = sum(total_wins),
pct_of_continent = round((total_wins / continent_total) * 100, 1)
) |>
arrange(desc(continent_total), desc(total_wins))
most_per_continent| birth_continent | gender | total_wins | continent_total | pct_of_continent |
|---|---|---|---|---|
| Europe | male | 501 | 529 | 94.7 |
| Europe | female | 28 | 529 | 5.3 |
| North America | male | 313 | 335 | 93.4 |
| North America | female | 22 | 335 | 6.6 |
| Asia | male | 71 | 82 | 86.6 |
| Asia | female | 11 | 82 | 13.4 |
| Africa | male | 23 | 29 | 79.3 |
| Africa | female | 6 | 29 | 20.7 |
| Oceania | male | 14 | 15 | 93.3 |
| Oceania | female | 1 | 15 | 6.7 |
| South America | male | 10 | 12 | 83.3 |
| South America | female | 2 | 12 | 16.7 |
Plot
ggplot(most_per_continent, aes(x = reorder(birth_continent, continent_total), y = total_wins, fill = gender)) +
geom_bar(stat = "identity", position = "dodge", width = 0.7) +
coord_flip() +
labs(
title = "Nobel Prize Gender Breakdown by Birth Continent",
x = "Birth Continent",
y = "Total Individual Wins",
fill = "Gender"
) +
theme_minimal() +
scale_fill_manual(values = c("female" = "lightcoral", "male" = "royalblue4"))To refer back to our question 1 for a moment, Europe has more winners than the other continents, but country-wise, the USA has had the most winners.
But in regard to gender, it seems like this is a male dominant data pull where there are less female than male laureates.
Per category, what year had the most winners?
years_most_winner <- clean_data |>
count(prize_category, award_year, name = "winner_count") |>
group_by(prize_category) |>
slice_max(order_by = winner_count, n = 1, with_ties = FALSE) |>
ungroup()
years_most_winner| prize_category | award_year | winner_count |
|---|---|---|
| Chemistry | 1946 | 3 |
| Economic Sciences | 1990 | 3 |
| Literature | 1904 | 2 |
| Peace | 1994 | 3 |
| Physics | 1903 | 3 |
| Physiology or Medicine | 1934 | 3 |
It seems that all of the winners for each category is within the 20th century.
Working with APIs can be difficult as it is a hassle to get the exact data that we want and going through the long data lists to extract it. Luckily with the Nobel Prize API, it did not need an API key so a bit of the struggle was taken off.
Then after analyzing the data, it was fascinating to me that there was a higher prize in one category than the other. Initially I had thought medicine or physics would be the top category but it had shocked me it was Economic Sciences. Similarly shocking that there are more male than females winning Nobel prizes, but also surprising that Europe has the most winners but in North America, the USA has more winners in 5/6 of the categories. Lastly, it is astonishing that there are not a lot of 21st century winners per category.
“Developer Zone.” NobelPrize.Org, https://www.nobelprize.org/about/developer-zone-2/. Accessed 4 Nov. 2026.