For this assignment we were asked to use a New York Times Application Programming Interface (API), read the JSON data and transform it to a dataframe.

library(knitr)
library(rjson)
suppressMessages(library(jsonlite))
suppressWarnings(library(ggplot2))

Show available New York Times book lists.

booklists<- fromJSON("http://api.nytimes.com/svc/books/v3/lists/names.json?api-key=56fec8351d568355fb3e456191f01316:13:29126896")
kable(booklists)
Copyright (c) 2016 The New York Times Company. All Rights Reserved.
list_name display_name list_name_encoded oldest_published_date newest_published_date updated
Combined Print and E-Book Fiction Combined Print & E-Book Fiction combined-print-and-e-book-fiction 2011-02-13 2016-04-10 WEEKLY
Combined Print and E-Book Nonfiction Combined Print & E-Book Nonfiction combined-print-and-e-book-nonfiction 2011-02-13 2016-04-10 WEEKLY
Hardcover Fiction Hardcover Fiction hardcover-fiction 2008-06-08 2016-04-10 WEEKLY
Hardcover Nonfiction Hardcover Nonfiction hardcover-nonfiction 2008-06-08 2016-04-10 WEEKLY
Trade Fiction Paperback Paperback Trade Fiction trade-fiction-paperback 2008-06-08 2016-04-10 WEEKLY
Mass Market Paperback Paperback Mass-Market Fiction mass-market-paperback 2008-06-08 2016-04-10 WEEKLY
Paperback Nonfiction Paperback Nonfiction paperback-nonfiction 2008-06-08 2016-04-10 WEEKLY
E-Book Fiction E-Book Fiction e-book-fiction 2011-02-13 2016-04-10 WEEKLY
E-Book Nonfiction E-Book Nonfiction e-book-nonfiction 2011-02-13 2016-04-10 WEEKLY
Hardcover Advice Hardcover Advice & Misc. hardcover-advice 2008-06-08 2013-04-21 WEEKLY
Paperback Advice Paperback Advice & Misc. paperback-advice 2008-06-08 2013-04-21 WEEKLY
Advice How-To and Miscellaneous Advice, How-To & Miscellaneous advice-how-to-and-miscellaneous 2013-04-28 2016-04-10 WEEKLY
Picture Books Children’s Picture Books picture-books 2008-06-08 2016-04-10 WEEKLY
Chapter Books Children’s Chapter Books chapter-books 2008-06-08 2012-12-09 WEEKLY
Childrens Middle Grade Children’s Middle Grade childrens-middle-grade 2012-12-16 2015-08-23 WEEKLY
Young Adult Young Adult young-adult 2012-12-16 2015-08-23 WEEKLY
Paperback Books Children’s Paperback Books paperback-books 2008-06-08 2012-12-09 WEEKLY
Childrens Middle Grade Hardcover Children’s Middle Grade Hardcover childrens-middle-grade-hardcover 2015-08-30 2016-04-10 WEEKLY
Childrens Middle Grade Paperback Children’s Middle Grade Paperback childrens-middle-grade-paperback 2015-08-30 2016-04-10 WEEKLY
Childrens Middle Grade E-Book Children’s Middle Grade E-Book childrens-middle-grade-e-book 2015-08-30 2016-04-10 WEEKLY
Young Adult Hardcover Young Adult Hardcover young-adult-hardcover 2015-08-30 2016-04-10 WEEKLY
Young Adult Paperback Young Adult Paperback young-adult-paperback 2015-08-30 2016-04-10 WEEKLY
Young Adult E-Book Young Adult E-Book young-adult-e-book 2015-08-30 2016-04-10 WEEKLY
Series Books Children’s Series series-books 2008-06-08 2016-04-10 WEEKLY
Hardcover Graphic Books Hardcover Graphic Books hardcover-graphic-books 2009-03-15 2016-04-10 WEEKLY
Paperback Graphic Books Paperback Graphic Books paperback-graphic-books 2009-03-15 2016-04-10 WEEKLY
Manga Manga manga 2009-03-15 2016-04-10 WEEKLY
Combined Print Fiction Combined Hardcover & Paperback Fiction combined-print-fiction 2011-02-13 2013-05-12 WEEKLY
Combined Print Nonfiction Combined Hardcover & Paperback Nonfiction combined-print-nonfiction 2011-02-13 2013-05-12 WEEKLY
Animals Animals animals 2014-09-07 2016-04-10 MONTHLY
Business Books Business business-books 2013-11-03 2016-04-10 MONTHLY
Celebrities Celebrities celebrities 2014-09-07 2016-04-10 MONTHLY
Crime and Punishment Crime and Punishment crime-and-punishment 2014-10-12 2016-04-10 MONTHLY
Culture Culture culture 2014-10-12 2016-04-10 MONTHLY
Education Education education 2014-10-12 2016-04-10 MONTHLY
Espionage Espionage espionage 2014-12-14 2016-04-10 MONTHLY
Expeditions Disasters and Adventures Expeditions, Disasters and Adventures expeditions-disasters-and-adventures 2014-12-14 2016-04-10 MONTHLY
Family Family family 2014-09-07 2016-04-10 MONTHLY
Fashion Manners and Customs Fashion, Manners and Customs fashion-manners-and-customs 2014-10-12 2016-04-10 MONTHLY
Food and Fitness Food and Fitness food-and-fitness 2013-09-01 2016-04-10 MONTHLY
Games and Activities Games and Activities games-and-activities 2014-10-12 2016-04-10 MONTHLY
Hardcover Business Books Hardcover Business Books hardcover-business-books 2011-07-03 2013-10-13 MONTHLY
Health Health health 2014-10-12 2016-04-10 MONTHLY
Humor Humor humor 2014-09-07 2016-04-10 MONTHLY
Indigenous Americans Indigenous Americans indigenous-americans 2014-12-14 2016-01-10 MONTHLY
Paperback Business Books Paperback Business Books paperback-business-books 2011-07-03 2013-10-13 MONTHLY
Hardcover Political Books Politics hardcover-political-books 2011-07-03 2016-04-10 MONTHLY
Race and Civil Rights Race and Civil Rights race-and-civil-rights 2014-12-14 2016-04-10 MONTHLY
Relationships Relationships relationships 2014-09-07 2016-04-10 MONTHLY
Religion Spirituality and Faith Religion, Spirituality and Faith religion-spirituality-and-faith 2014-09-07 2016-04-10 MONTHLY
Science Science science 2013-04-14 2016-04-10 MONTHLY
Sports Sports sports 2014-03-02 2016-04-10 MONTHLY
Travel Travel travel 2014-09-07 2016-04-10 MONTHLY

Show Hardcover Fiction bestsellers.

Subset to remove unneeded columns.

fictionhardcover <- fromJSON("http://api.nytimes.com/svc/books/v3/lists.json?list=hardcover-fiction&api-key=56fec8351d568355fb3e456191f01316:13:29126896")

fhbooks<- fictionhardcover$results
dffh<- as.data.frame(fhbooks)

# Attempt to make a plot of book title vs. weeks on list. Not sure why this didn't work.
#dffh$weeks_on_list<-as.numeric(dffh$weeks_on_list)

#ggplot(dffh, aes(x=title, y=weeks_on_list, fill=title)) + geom_bar(stat="identity") + ggtitle("Fiction Hardcover Weeks on List")+ theme(axis.text=element_text(angle=60))+ labs(x="Book",y="Weeks On List")


dffh<- subset(dffh[,c(1:7,12)])
kable(dffh)
list_name display_name bestsellers_date published_date rank rank_last_week weeks_on_list book_details
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 1 0 1 FOOL ME ONCE, A retired Army helicopter pilot faces combat-related nightmares and mysteries concerning the deaths of her husband and sister., by Harlan Coben, Harlan Coben, , 0, , Dutton, 9780525955092, 0525955097
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 2 1 2 PRIVATE PARIS, Jack Morgan, the head of the Private global investigative agency, probes the murders of members of the French cultural elite., by James Patterson and Mark Sullivan, James Patterson and Mark Sullivan, , 0, , Little, Brown, 9780316407052, 0316407054
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 3 0 1 THE NEST, Siblings in a dysfunctional New York family must grapple with a reduced inheritance., by Cynthia D’Aprix Sweeney, Cynthia D’Aprix Sweeney, , 0, , Ecco/HarperCollins, 9780062414212, 0062414216
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 4 2 2 PROPERTY OF A NOBLEWOMAN, Two New Yorkers reconstruct the history of a young woman and a love affair at the time of World War II., by Danielle Steel, Danielle Steel, , 0, , Delacorte, 9780345531063, 034553106X
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 5 3 99 ALL THE LIGHT WE CANNOT SEE, The lives of a blind French girl and a gadget-obsessed German boy before and during World War II.  , by Anthony Doerr, Anthony Doerr, , 0, , Scribner, 9781476746586, 1476746583
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 6 6 63 THE GIRL ON THE TRAIN, A psychological thriller set in the environs of London., by Paula Hawkins, Paula Hawkins, , 0, , Riverhead, 9781594633669, 1594633665
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 7 0 1 THE SUMMER BEFORE THE WAR, Life in Sussex, England, at the beginning of World War I., by Helen Simonson, Helen Simonson, , 0, , Random House, 9780812993103, 0812993101
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 8 4 56 THE NIGHTINGALE, Two sisters in World War II France: one struggling to survive in the countryside, the other joining the Resistance in Paris., by Kristin Hannah, Kristin Hannah, , 0, , St. Martin’s, 9780312577223, 0312577222
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 9 5 3 OFF THE GRID, The 16th Joe Pickett novel features Nate Romanowski and a search for a domestic terror cell., by C. J. Box, C J Box, , 0, , Putnam, 9780399176609, 0399176608
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 10 8 4 THE GANGSTER, In 1906, the New York detective Isaac Bell contends with a crime boss., by Clive Cussler and Justin Scott, Clive Cussler and Justin Scott, , 0, , Putnam, 9780399175954, 0399175954
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 11 13 8 AFTER YOU, In a sequel to “Me Before You,” Louisa Clark tries to put her life back together after the death of Will Traynor, and joins a grief support group that may lead her to new love., by Jojo Moyes, Jojo Moyes, , 0, , Pamela Dorman/Viking, 9780525426592, 0525426590
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 12 12 35 GO SET A WATCHMAN, In the mid-1950s, a grown-up Jean Louise Finch returns home to find that her adored father is not as perfect as she believed., by Harper Lee, Harper Lee, , 0, , Harper, 9780062409850, 0062409859
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 13 0 10 MY NAME IS LUCY BARTON, A woman struggles with memories of her impoverished and disturbing childhood., by Elizabeth Strout, Elizabeth Strout, , 0, , Random House, 9781400067695, 1400067693
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 14 10 3 THE STEEL KISS, Lincoln Rhyme and his new assistant, also a paraplegic, investigate a domestic terrorist who sabotages equipment., by Jeffery Deaver, Jeffery Deaver, , 0, , Grand Central, 9781455536344, 1455536342
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 15 7 2 DEEP BLUE, Doc Ford, a Florida marine biologist and former government agent, tracks an American who is working with ISIS. The 23rd book in a series., by Randy Wayne White, Randy Wayne White, , 0, , Putnam, 9780399173516, 039917351X
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 16 15 6 THE WIDOW, When a suspect in a missing-child case dies, reporters and the police wrongly think they’ll get the real story from his widow., by Fiona Barton, Fiona Barton, , 0, , New American Library, 9781101990261, 1101990260
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 17 0 0 A FEW OF THE GIRLS, A collection of the stories that spans the career of the Irish writer, who died in 2012., by Maeve Binchy, Maeve Binchy, , 0, , Knopf, 9781101947418, 1101947411
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 18 0 0 THE SWANS OF FIFTH AVENUE, A novel based on the friendship between Truman Capote and Babe Paley and her coterie, which began in the 1950s and ended 20 years later in scandal., by Melanie Benjamin, Melanie Benjamin, , 0, , Delacorte, 9780345528698, 0345528697
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 19 0 0 AT THE EDGE OF THE ORCHARD, Two generations of 19th-century American pioneer life unfold in Chevalier’s eighth novel., by Tracy Chevalier, Tracy Chevalier, , 0, , Viking, 9780525953005, 0525953000
Hardcover Fiction Hardcover Fiction 2016-03-26 2016-04-10 20 0 0 FIRE TOUCHED, The shape-shifter Mercy Thompson and her Alpha werewolf mate, Adam, protect a stolen human child., by Patricia Briggs, Patricia Briggs, , 0, , Ace, 9780425256763, 0425256766

Show Paperback Trade Fiction bestsellers.

Subset to remove unneeded columns.

fictionpaperback<- fromJSON("http://api.nytimes.com/svc/books/v3/lists.json?list=trade-fiction-paperback&api-key=56fec8351d568355fb3e456191f01316:13:29126896")
                     
fpbooks<- fictionpaperback$results
dffp<- as.data.frame(fpbooks)
dffp<- subset(dffp[,c(1:7,12)])
kable(dffp)
list_name display_name bestsellers_date published_date rank rank_last_week weeks_on_list book_details
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 1 0 68 ME BEFORE YOU, A young woman who has barely been farther afield than her English village finds herself while caring for a wealthy, embittered quadriplegic., by Jojo Moyes, Jojo Moyes, , 0, , Penguin, 9780143124542, 0143124544
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 2 0 1 THE GUILTY, Will Robie, the government’s ace assassin, learns that his estranged father is charged with murder, but his investigation is unwelcome., by David Baldacci, David Baldacci, , 0, , Grand Central, 9781455586431, 1455586439
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 3 0 50 ROOM, The world of the 5-year-old boy who narrates this novel is the 11-by-11-foot room in which his mother is being held. The basis of the movie., by Emma Donoghue, Emma Donoghue, , 0, , Back Bay/Little, Brown, 9780316098328, 0316098329
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 4 0 22 BROOKLYN, An unsophisticated young Irishwoman leaves her home for New York in the 1950s. The basis of the movie., by Colm Toibin, Colm Toibin, , 0, , Scribner, 9781501106477, 1501106473
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 5 0 30 MY BRILLIANT FRIEND, The first installment in the author’s Neapolitan series, about the lifelong friendship between two women., by Elena Ferrante, Elena Ferrante, , 0, , Europa, 9781609450786, 1609450787
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 6 0 13 A MAN CALLED OVE, An angry old curmudgeon gets new next-door neighbors, and things are about to change for all of them., by Fredrik Backman, Fredrik Backman, , 0, , Washington Square, 9781476738024, 1476738025
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 7 0 74 THE MARTIAN, Separated from his crew, an astronaut embarks on a quest to stay alive on Mars. The basis of the movie., by Andy Weir, Andy Weir, , 0, , Broadway, 9780553418026, 0553418025
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 8 0 14 THE REVENANT, Left for dead after a mauling, the master tracker Hugh Glass is consumed by a singular desire for revenge; an inspiration for the 2015 film., by Michael Punke, Michael Punke, , 0, , Picador, 9781250072689, 1250072689
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 9 0 8 A LITTLE LIFE, Four college friends, one with a traumatic past, move to New York seeking fame and fortune., by Hanya Yanagihara, Hanya Yanagihara, , 0, , Anchor, 9780804172707, 0804172706
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 10 0 1 THE LITTLE PARIS BOOKSHOP, Monsieur Perdu dispenses books to help mend broken hearts and decides to finally confront his own long-ago heartbreak., by Nina George, Nina George, , 0, , Broadway, 9780553418798, 0553418793
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 11 0 0 THE ALCHEMIST, A Spanish shepherd boy ventures to Egypt in search of treasure., by Paulo Coelho, Paulo Coelho, , 0, , HarperOne/HarperCollins, 9780062315007, 0062315005
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 12 0 0 READY PLAYER ONE, It’s 2044, life on a resource-depleted Earth has grown increasingly grim, and the key to a vast fortune is hidden in a virtual-reality world., by Ernest Cline, Ernest Cline, , 0, , Broadway, 9780307887443, 0307887448
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 13 0 0 BIG LITTLE LIES, A death at an elementary school’s trivia night reveals the rivalries among the parents and raises questions of murder., by Liane Moriarty, Liane Moriarty, , 0, , Berkley, 9780425274866, 0425274861
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 14 0 0 THE STORY OF A NEW NAME, Book 2 of the Neapolitan series continues the story of two women and their lifelong friendship., by Elena Ferrante, Elena Ferrante, , 0, , Europa, 9781609451349, 1609451341
Trade Fiction Paperback Paperback Trade Fiction 2016-03-26 2016-04-10 15 0 0 EVERY FIFTEEN MINUTES, A psychiatrist becomes the target of a sociopath., by Lisa Scottoline, Lisa Scottoline, , 0, , St. Martin’s Griffin, 9781250010124, 1250010128

Questions

Why is the “rank last week” value zero? Is this a data frame error?

How can a bar plot be generated of weeks on list vs. book title?