This assignment applied JSON data from the Nobel Prize API to investigate patterns in Nobel Prize awards. Implementing R, I would analyze categories, laureates’ birth nations, historical trends, and international research connections. The objective is to display how JSON data can be transformed into tidy data frames to respond compelling queries.
library(jsonlite)
library(dplyr)
library(tidyr)
library(ggplot2)
library(purrr)
url <- "https://api.nobelprize.org/v1/laureate.json"
raw <- fromJSON(url, simplifyVector = FALSE)
laureates <- map_dfr(raw$laureates, function(x) {
tibble(
id = x$id,
name = paste(x$firstname %||% "",
x$surname %||% ""),
birth_country = x$bornCountry %||% NA_character_,
gender = x$gender %||% NA_character_
)
})
awards <- map_dfr(raw$laureates, function(x) {
map_dfr(x$prizes, function(p) {
tibble(
id = x$id,
year = as.integer(p$year),
category = p$category
)
})
})
head(laureates)
## # A tibble: 6 × 4
## id name birth_country gender
## <chr> <chr> <chr> <chr>
## 1 1 Wilhelm Conrad … Prussia (now… male
## 2 2 Hendrik A. Lore… the Netherla… male
## 3 3 Pieter Zeeman the Netherla… male
## 4 4 Henri Becquerel France male
## 5 5 Pierre Curie France male
## 6 6 Marie Curie Russian Empi… female
head(awards)
## # A tibble: 6 × 3
## id year category
## <chr> <int> <chr>
## 1 1 1901 physics
## 2 2 1902 physics
## 3 3 1902 physics
## 4 4 1903 physics
## 5 5 1903 physics
## 6 6 1903 physics
## Q1 - Which Nobel Prize categories contain the most laureate awards?
``` r
q1 <- awards |>
count(category, sort = TRUE)
q1
## # A tibble: 6 × 2
## category n
## <chr> <int>
## 1 medicine 235
## 2 physics 231
## 3 chemistry 202
## 4 peace 144
## 5 literature 123
## 6 economics 101
ggplot(q1, aes(x = reorder(category, n), y = n)) +
geom_col(fill = "steelblue") +
coord_flip() +
labs(
title = "Nobel Laureate Awards by Category",
x = "Category",
y = "Number of laureate awards"
) +
theme_minimal()
## Q3 - Which birth nation have produced the most laureates?
``` r
q2 <- laureates |>
filter(!is.na(birth_country)) |>
count(birth_country, sort = TRUE) |>
head(10)
q2
## # A tibble: 10 × 2
## birth_country n
## <chr> <int>
## 1 USA 299
## 2 United Kingdom 94
## 3 Germany 69
## 4 France 61
## 5 Japan 31
## 6 Sweden 30
## 7 Canada 23
## 8 the Netherlands 20
## 9 Switzerland 19
## 10 Italy 18
Q3 - How have Nobel laureate awards changed by decade ?
``` r
q3 <- awards |>
mutate(decade = (year %/% 10) * 10) |>
count(decade)
q3
## # A tibble: 13 × 2
## decade n
## <dbl> <int>
## 1 1900 57
## 2 1910 40
## 3 1920 54
## 4 1930 56
## 5 1940 43
## 6 1950 72
## 7 1960 79
## 8 1970 104
## 9 1980 97
## 10 1990 104
## 11 2000 123
## 12 2010 121
## 13 2020 86
ggplot(q3, aes(x = decade, y = n)) +
geom_line() +
geom_point() +
labs(
title = "Nobel Laureate Awards by Decade",
x = "Decade",
y = "Number of laureate awards"
) +
theme_minimal()
Q4 - Which birth countries have produced the most laureates who won awards in different categories?
``` r
q4 <- laureates |>
inner_join(awards, by = "id") |>
filter(!is.na(birth_country)) |>
group_by(id, name, birth_country) |>
summarise(
categories = n_distinct(category),
.groups = "drop"
) |>
filter(categories > 1) |>
count(birth_country, sort = TRUE)
q4
## # A tibble: 2 × 2
## birth_country n
## <chr> <int>
## 1 Russian Empire (now Poland) 1
## 2 USA 1
``` ## Conclusion The analysis indicades that Novel Prize JSON data can indeed be retrieved, cleaned, and transformed using R. The fours questions hoped to implement a means to distinguish award categories, nations, and time periods, in which a final question utilizes a join to pinpoint laureates acknowledged in various fields.
Restrctions can exist in terms of country information, historical shifts in nation names, and discrepencies amongst laureate counts and awards quantity. Potential analysis can hope to explore gender representation or international research collaboration.