Loading libraries
library(jsonlite)
library(httr)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Constructing an interface with required API and checking the
response
# link to the API output as a JSON file
url_json <- "https://api.nytimes.com/svc/movies/v2/critics/all.json?api-key=VAhjWqxLrMQTPsvIOYxaH7gFuKWE79en"
#get the raw json into R
resp <- GET(url_json)
resp
## Response [https://api.nytimes.com/svc/movies/v2/critics/all.json?api-key=VAhjWqxLrMQTPsvIOYxaH7gFuKWE79en]
## Date: 2022-10-30 20:31
## Status: 200
## Content-Type: application/json; charset=utf-8
## Size: 13.9 kB
Reading movie critics JSON data and converting it into a R
dataframe
critics_data<- fromJSON(rawToChar(resp$content))%>% data.frame
glimpse(critics_data)
## Rows: 82
## Columns: 9
## $ status <chr> "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "…
## $ copyright <chr> "Copyright (c) 2022 The New York Times Company. A…
## $ num_results <int> 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 8…
## $ results.display_name <chr> "A. O. Scott", "Renata Adler", "Robert Alden", "E…
## $ results.sort_name <chr> "A. O. Scott", "Adler, Renata", "Alden, Robert", …
## $ results.status <chr> "full-time", "part-time", "", "part-time", "part-…
## $ results.bio <chr> "A. O. Scott joined The New York Times as a film …
## $ results.seo_name <chr> "A-O-Scott", "Renata-Adler", "Robert-Alden", "Eug…
## $ results.multimedia <df[,1]> <data.frame[26 x 1]>
Data tidying and subsetting
#Renaming two columns
critics_data<-rename(critics_data,critic_name=results.display_name,critic_status=results.status)
#Sub setting data frame with new column names
critics_data1<-select(critics_data,critic_name,critic_status)
head(critics_data1)
## critic_name critic_status
## 1 A. O. Scott full-time
## 2 Renata Adler part-time
## 3 Robert Alden
## 4 Eugene Archer part-time
## 5 Miriam Bale part-time
## 6 Felicity Barringer part-time
#Replace empty value with NA in critic_status column
critics_data1$critic_status[critics_data1$critic_status==''] <- NA
head(critics_data1)
## critic_name critic_status
## 1 A. O. Scott full-time
## 2 Renata Adler part-time
## 3 Robert Alden <NA>
## 4 Eugene Archer part-time
## 5 Miriam Bale part-time
## 6 Felicity Barringer part-time
#Finding critics status count data
critics_status_count_data <- critics_data1 %>% count(critic_status)
critics_status_count_data
## critic_status n
## 1 full-time 3
## 2 part-time 56
## 3 <NA> 23
Plotting critics status based on their occuring number
ggplot(data=critics_status_count_data, aes(x=critic_status, y=n)) +
geom_bar(stat="identity") +
labs(
x = "Critic Status",
y = "Number of Critic Status",
title = "The number of critic status"
) +
coord_flip()

Conclusion: In this assignment, I chose movie critics data for all
reviewer from New York Times Movie Review API.I collected JSON data
through a API connection and transformed that JSON data into a R data
frame. Finally, I plotted a bar graph to see the critics status based on
their occuring numbers.