Assignment Overview
The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis(https://developer.nytimes.com/apis)
You’ll need to start by signing up for an API key.
Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it into an R DataFrame.
Load Package
library(httr)
library(jsonlite)
library(knitr)
library(DT)
library(stringr)
library(dplyr)
Read movie information
url<-("https://api.nytimes.com/svc/movies/v2/reviews/search.json?critics-pick=Y&order=by-title&api-key=eTlUJikeG81CLJ3wJYvBfxs6UAACelfi")
Create a dataframe and display results
movie_reviews<- fromJSON(url) %>%
as.data.frame() %>%
select(5, 6, 7, 8)
names(movie_reviews) <- str_replace_all(names(movie_reviews), "results.", "")
datatable(movie_reviews)
Fill null values in rating column
movie_reviews$mpaa_rating[movie_reviews$mpaa_rating == ''] <- 'Not Rated'
Show bar chart of rating type
library(ggplot2)
movie_reviews %>%
ggplot(aes(x=mpaa_rating, fill=mpaa_rating)) + geom_bar(position = "dodge") +# plot
ggtitle("Movie Rating bar plot")
Top reviews are for not rated movies
Show bar chart of critics
movie_reviews %>%
ggplot(aes(x=byline, fill=byline)) + geom_bar(position = "dodge") +# plot
ggtitle("Critic bar plot")
Top reviews are done by : Jeannette Catsoulis Manohla Dargis Stephen Holden