Using the New York Times Books API in R

Author

Guibril Ramde

Approach

For this assignment, I selected the **New York Times Books API**, specifically the endpoint for the current **hardcover fiction best seller list**. The purpose of this analysis is to retrieve data from the API, convert the JSON response into a tidy data frame in R, and examine the current best-selling books on the list.

To access the API securely, I created a New York Times Developer Network account and generated an API key. Instead of hard coding the key directly in the script, I stored it in my `.Renviron` file and accessed it in R using `Sys.getenv(“NYT_API_KEY”)`. This approach protects the key from being exposed in a public GitHub repository.

Next, I used the `httr` package to make a GET request to the Books API endpoint. After receiving the response, I used `jsonlite` to parse the JSON content. Since the full API response contains nested fields and metadata, I extracted the `books` portion from `data$results`, which contains the actual book records for the selected list.

I then transformed the nested JSON data into a tidy tibble and selected the variables most relevant for analysis, such as rank, title, author, publisher, and weeks on list. Any unnecessary nested fields were excluded in order to produce a cleaner and more readable data frame.

Finally, I used the cleaned data to perform a small analysis of the current hardcover fiction best sellers and included a simple table or visualization to help answer an interesting question based on the API results.

##Selecting The endpoint and brief description (API Selected)
I selected the New York Times Books API endpoint for the current hardcover fiction list:
`https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json`
This endpoint returns the current New York Times hardcover fiction best seller list, including information such as title, author, publisher, current rank, previous rank, and weeks on the list.

##Request parameters
The request used the following parameter:
- `api-key`: my New York Times API key stored securely in `.Renviron`
The list chosen for this project was `hardcover-fiction`, which is included in the endpoint path.

##Question of Interest
Which books are currently ranked highest on the New York Times hardcover fiction best seller list, and how does their current position compare with their popularity over time, as measured by weeks on the list and previous-week rank?

Coding Section

library(httr)
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tibble' was built under R version 4.5.2
Warning: package 'tidyr' was built under R version 4.5.2
Warning: package 'readr' was built under R version 4.5.2
Warning: package 'purrr' was built under R version 4.5.2
Warning: package 'dplyr' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)

Attaching package: 'jsonlite'

The following object is masked from 'package:purrr':

    flatten
library(tibble)
api_key <- Sys.getenv("NYT_API_KEY")

url <- paste0("https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=", api_key)

response <- GET(url)
response
Response [https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json?api-key=46subwwurszHj6XgYFRuBxQTLHAgmh2kDVklkILA6Efo3Omv]
  Date: 2026-03-29 20:44
  Status: 200
  Content-Type: application/json; charset=utf-8
  Size: 24 kB
{"status":"OK","copyright":"Copyright (c) 2026 The New York Times Company. Al...
data <- fromJSON(content(response, "text"))

data
$status
[1] "OK"

$copyright
[1] "Copyright (c) 2026 The New York Times Company. All Rights Reserved."

$num_results
[1] 15

$last_modified
[1] "2026-03-25T22:37:48Z"

$results
$results$display_name
[1] "Hardcover Fiction"

$results$list_name
[1] "Hardcover Fiction"

$results$list_name_encoded
[1] "hardcover-fiction"

$results$previous_published_date
[1] "2026-03-29"

$results$published_date
[1] "2026-04-05"

$results$bestsellers_date
[1] "2026-03-21"

$results$normal_list_ends_at
[1] 15

$results$updated
[1] "WEEKLY"

$results$list_id
[1] 1

$results$uri
[1] "nyt://bestsellerslist/aa7d0d6a-4071-5737-ad6e-079ba050ef04"

$results$books
   age_group                                        amazon_product_url
1            https://www.amazon.com/dp/0316579831?tag=thenewyorktim-20
2            https://www.amazon.com/dp/0593798430?tag=thenewyorktim-20
3            https://www.amazon.com/dp/1538743027?tag=thenewyorktim-20
4            https://www.amazon.com/dp/125033781X?tag=thenewyorktim-20
5            https://www.amazon.com/dp/0593722590?tag=thenewyorktim-20
6            https://www.amazon.com/dp/0593820266?tag=thenewyorktim-20
7            https://www.amazon.com/dp/1250405408?tag=thenewyorktim-20
8            https://www.amazon.com/dp/0525659188?tag=thenewyorktim-20
9            https://www.amazon.com/dp/1250439205?tag=thenewyorktim-20
10           https://www.amazon.com/dp/B094X214V9?tag=thenewyorktim-20
11           https://www.amazon.com/dp/0385548982?tag=thenewyorktim-20
12           https://www.amazon.com/dp/B0DQ72PKP2?tag=thenewyorktim-20
13           https://www.amazon.com/dp/0593851099?tag=thenewyorktim-20
14           https://www.amazon.com/dp/0593955978?tag=thenewyorktim-20
15           https://www.amazon.com/dp/B08V8877BY?tag=thenewyorktim-20
   article_chapter_link asterisk                          author
1                              0 Viola Davis and James Patterson
2                              0                  Virginia Evans
3                              0                    Sandra Brown
4                              0                    Alice Feeney
5                              0                        Ava Reid
6                              0                   Matt Dinniman
7                              0               Carissa Broadbent
8                              0                    Tayari Jones
9                              0            Christopher Buehlman
10                             0                   Matt Dinniman
11                             0                    John Grisham
12                             0                        SenLinYu
13                             0                        C.J. Box
14                             0                   Matt Dinniman
15                             0                   Matt Dinniman
                                                      book_image
1  https://static01.nyt.com/bestsellers/images/9780316579834.jpg
2  https://static01.nyt.com/bestsellers/images/9780593798430.jpg
3  https://static01.nyt.com/bestsellers/images/9781538743027.jpg
4  https://static01.nyt.com/bestsellers/images/9781250337818.jpg
5  https://static01.nyt.com/bestsellers/images/9780593722596.jpg
6  https://static01.nyt.com/bestsellers/images/9780593820261.jpg
7  https://static01.nyt.com/bestsellers/images/9781250405401.jpg
8  https://static01.nyt.com/bestsellers/images/9780525659181.jpg
9  https://static01.nyt.com/bestsellers/images/9781250439208.jpg
10 https://static01.nyt.com/bestsellers/images/9780593820285.jpg
11 https://static01.nyt.com/bestsellers/images/9780385548984.jpg
12 https://static01.nyt.com/bestsellers/images/9780593972700.jpg
13 https://static01.nyt.com/bestsellers/images/9780593851098.jpg
14 https://static01.nyt.com/bestsellers/images/9780593955970.jpg
15 https://static01.nyt.com/bestsellers/images/9780593820247.jpg
   book_image_height book_image_width
1                500              322
2                  0                0
3                500              331
4                  0                0
5                500              313
6                  0                0
7                500              327
8                500              331
9                400              312
10               400              312
11                 0                0
12                 0                0
13               500              332
14               500              331
15               400              312
                                                        book_review_link
1                                                                       
2                                                                       
3                                                                       
4                                                                       
5                                                                       
6                                                                       
7                                                                       
8  https://www.nytimes.com/2026/02/19/books/review/kin-tayari-jones.html
9                                                                       
10                                                                      
11                                                                      
12                                                                      
13                                                                      
14                                                                      
15                                                                      
                                          book_uri
1  nyt://book/6f72e477-90a5-5cbc-9f2d-d96c1590adeb
2  nyt://book/ee6e7478-d847-5258-a579-f9ef0ed9c301
3  nyt://book/2a0aead0-b991-5fcd-bead-d15428ad309d
4  nyt://book/0461987c-33f3-5d5d-a2ad-f03226f1ca3a
5  nyt://book/be7ea6b9-7f6a-59f3-aae0-f19d20c8e552
6  nyt://book/e84133b7-b087-54fe-aa42-0605dff68e6f
7  nyt://book/9de5334b-3247-5c47-9651-8edffff957a9
8  nyt://book/aa33c150-8324-558d-b307-2e132de2ea01
9  nyt://book/51e94526-6db1-51fd-bdf1-31a295cb16b3
10 nyt://book/87acdbd7-b1e9-576a-a712-830df9715448
11 nyt://book/b4d35d23-bb5e-5f9c-b842-01c4352fe4dc
12 nyt://book/e9c567d8-7c38-5cb8-88e5-ba46078e2144
13 nyt://book/0c3b50f4-86ea-5c00-88d8-aa28a21d2035
14 nyt://book/253e5724-9547-5551-b50d-97d71cbcfa45
15 nyt://book/b684926b-80a9-5829-9c38-876d4d3382b7
                          contributor contributor_note             created_date
1  by Viola Davis and James Patterson                  2026-03-18T22:38:16.974Z
2                   by Virginia Evans                   2026-03-04T23:40:21.28Z
3                     by Sandra Brown                  2026-03-25T22:37:40.571Z
4                     by Alice Feeney                  2026-03-04T23:39:58.687Z
5                         by Ava Reid                  2026-03-25T22:37:40.835Z
6                    by Matt Dinniman                  2026-03-04T23:39:58.983Z
7                by Carissa Broadbent                  2026-03-25T22:37:40.991Z
8                     by Tayari Jones                  2026-03-04T23:40:21.534Z
9             by Christopher Buehlman                  2026-03-25T23:53:45.841Z
10                   by Matt Dinniman                   2026-03-25T22:37:41.16Z
11                    by John Grisham                  2026-03-04T23:39:59.118Z
12                        by SenLinYu                  2026-03-04T23:39:58.831Z
13                        by C.J. Box                  2026-03-04T23:39:58.173Z
14                   by Matt Dinniman                  2026-03-25T22:37:41.297Z
15                   by Matt Dinniman                  2025-10-22T22:37:44.854Z
   dagger
1       0
2       0
3       0
4       0
5       0
6       0
7       0
8       0
9       0
10      0
11      0
12      0
13      0
14      0
15      0
                                                                                                                              description
1                                             Judge Mary Stone oversees an ethically complex case in her courtroom in Union Springs, Ala.
2                   Letters from someone she used to know push Sybil Van Antwerp toward revisiting her past and finding a way to forgive.
3             The mutual attraction between Detective Mitch Haskell and his therapist may hinder his attempt to avenge his murdered wife.
4                                                            In an old house in a seaside town, things may not be what they appear to be.
5                                                            Passion and revenge fuel Agnes as she seeks to recapture her family’s honor.
6                  The second book in the "Dungeon Crawler Carl" series. Carl and Donut confront an ancient spell and heightened dangers.
7            The third book in the War of Lost Hearts series. Tisaanah, Maxatarius and Aefe are caught in an upheaval between two worlds.
8  Vernice and Annie, two neighbors without mothers in Louisiana, go on divergent paths in life and are brought back together by tragedy.
9                 In 1348, a disgraced knight shepherds an orphan of the Black Death and winds up on a battlefield of conflicting forces.
10               The third book in the "Dungeon Crawler Carl" series. Carl and Donut are up against a subway system filled with monsters.
11                              When Simon Latch, a lawyer in rural Virginia, is accused of murder, he goes in search of the real killer.
12                                          After the war, an imprisoned alchemist is sent to a necromancer to recover her lost memories.
13             The 26th book in the Joe Pickett series. After Joe takes a gunshot to the head, his daughters seek to find out who did it.
14                                The fourth book in the Dungeon Crawler Carl series. Obstacles abound on the fifth floor of the dungeon.
15                            A Coast Guard vet named Carl and his ex-girlfriend’s cat, Princess Donut, are trapped in a fantasy dungeon.
   first_chapter_link price primary_isbn10 primary_isbn13             publisher
1                      0.00                 9780316579834 Little, Brown and JVL
2                      0.00                 9780593798430                 Crown
3                      0.00                 9781538743027         Grand Central
4                      0.00                 9781250337818          Pine & Cedar
5                      0.00                 9780593722596               Del Rey
6                      0.00                 9780593820261                   Ace
7                      0.00                 9781250405401               Bramble
8                      0.00                 9780525659181                 Knopf
9                      0.00                 9781250439208         Tor Nightfire
10                     0.00                 9780593820285                   Ace
11                     0.00                 9780385548984             Doubleday
12                     0.00                 9780593972700               Del Rey
13                     0.00                 9780593851098                Putnam
14                     0.00                 9780593955970                   Ace
15                     0.00                 9780593820247                   Ace
   rank rank_last_week sunday_review_link                            title
1     1              1                                         JUDGE STONE
2     2              3                                   THE CORRESPONDENT
3     3              0                                           BLOODLUST
4     4              8                                   MY HUSBAND'S WIFE
5     5              0                                          INNAMORATA
6     6              5                            CARL'S DOOMSDAY SCENARIO
7     7              0                            MOTHER OF DEATH AND DAWN
8     8              4                                                 KIN
9     9              7                                   BETWEEN TWO FIRES
10   10             12                    THE DUNGEON ANARCHIST'S COOKBOOK
11   11             10                                           THE WIDOW
12   12             11                                          ALCHEMISED
13   13              6                                      THE CROSSROADS
14   14              0                          THE GATE OF THE FERAL GODS
15   15              0                                DUNGEON CRAWLER CARL
               updated_date weeks_on_list           isbns
1  2026-03-18T22:38:16.974Z             2 , 9780316579834
2   2026-03-04T23:40:21.28Z            21 , 9780593798430
3  2026-03-25T22:37:40.571Z             1 , 9781538743027
4  2026-03-04T23:39:58.687Z             8 , 9781250337818
5  2026-03-25T22:37:40.835Z             1 , 9780593722596
6  2026-03-04T23:39:58.983Z            10 , 9780593820261
7  2026-03-25T22:37:40.991Z             1 , 9781250405401
8  2026-03-04T23:40:21.534Z             4 , 9780525659181
9  2026-03-25T23:53:45.841Z             3 , 9781250439208
10  2026-03-25T22:37:41.16Z             5 , 9780593820285
11 2026-03-04T23:39:59.118Z            22 , 9780385548984
12 2026-03-04T23:39:58.831Z            26 , 9780593972700
13 2026-03-04T23:39:58.173Z             4 , 9780593851098
14 2026-03-25T22:37:41.297Z             2 , 9780593955970
15 2025-10-22T22:37:44.854Z            12 , 9780593820247
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    buy_links
1                                        Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0316579831?tag=thenewyorktim-20, https://goto.applebooks.apple/9780316579834?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780316579834&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fjudge-stone-james-patterson%2F1148464105%3Fean%3D9780316579834&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FJudge-Stone%2FJames-Patterson%2F9780316579834, https://bookshop.org/a/3546/9780316579834
2                Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593798430?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593798430?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593798430&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-correspondent-virginia-evans%2F1146138272%3Fean%3D9780593798430&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fsearch%3Fquery%3DTHE%2520CORRESPONDENT%2520by%2520Virginia%2520Evans, https://bookshop.org/a/3546/9780593798430
3                                                  Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1538743027?tag=thenewyorktim-20, https://goto.applebooks.apple/9781538743027?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781538743027&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fbloodlust-sandra-brown%2F1114301748%3Fean%3D9781538743027&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FBloodlust%2FSandra-Brown%2F9781538743027, https://bookshop.org/a/3546/9781538743027
4                                    Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/125033781X?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250337818?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781250337818&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fmy-husbands-wife-alice-feeney%2F1147242018%3Fean%3D9781250337818&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FMy-Husbands-Wife%2FAlice-Feeney%2F9781250337818, https://bookshop.org/a/3546/9781250337818
5                                                        Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593722590?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593722596?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593722596&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Finnamorata-ava-reid%2F1147669401%3Fean%3D9780593722596&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FInnamorata%2FAva-Reid%2F9780593722596, https://bookshop.org/a/3546/9780593722596
6                    Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593820266?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820261?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593820261&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fcarls-doomsday-scenario-matt-dinniman%2F1145070342%3Fean%3D9780593820261&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FCarls-Doomsday-Scenario%2FMatt-Dinniman%2F9780593820261, https://bookshop.org/a/3546/9780593820261
7                 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1250405408?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250405401?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9781250405401&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fmother-of-death-and-dawn-carissa-broadbent%2F1141041635%3Fean%3D9781250405401&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FMother-Death-Dawn%2FCarissa-Broadbent%2F9781250405401, https://bookshop.org/a/3546/9781250405401
8                                                              Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0525659188?tag=thenewyorktim-20, https://goto.applebooks.apple/9780525659181?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780525659181&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fkin-tayari-jones%2F1148177459%3Fean%3D9780525659181&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FKin%2FTayari-Jones%2F9780525659181, https://bookshop.org/a/3546/9780525659181
9                                                                                                                           Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/1250439205?tag=thenewyorktim-20, https://goto.applebooks.apple/9781250439208?at=10lIEQ, https://www.barnesandnoble.com/w/between-two-fires-christopher-buehlman/1108799136?ean=9781250439208, https://www.booksamillion.com/p/Between-Two-Fires/Christopher-Buehlman/9781250439208, https://bookshop.org/p/books/between-two-fires-christopher-buehlman/0f55d0b868b5b4f9?ean=9781250439208&next=t
10                                                                                                                    Amazon, Apple Books, Barnes and Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B094X214V9?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820285?at=10lIEQ, https://www.barnesandnoble.com/w/the-dungeon-anarchists-cookbook-matt-dinniman/1145437166?ean=9780593820285, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDungeon-Anarchists-Cookbook%2FMatt-Dinniman%2F9780593820285, https://bookshop.org/a/3546/9780593820285
11                                                     Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0385548982?tag=thenewyorktim-20, https://goto.applebooks.apple/9780385548984?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780385548984&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-widow-john-grisham%2F1147191431%3Fean%3D9780385548984&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FWidow%2FJohn-Grisham%2F9780385548984, https://bookshop.org/a/3546/9780385548984
12                                                 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B0DQ72PKP2?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593972717?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593972700&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Falchemised-senlinyu%2F1146838848%3Fean%3D9780593972700&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fsearch%3Fquery%3DALCHEMISED%2520by%2520SenLinYu, https://bookshop.org/a/3546/9780593972717
13                                                     Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593851099?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593851098?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593851098&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-crossroads-c-j-box%2F1147476791%3Fean%3D9780593851098&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FCrossroads%2FC-J-Box%2F9780593851098, https://bookshop.org/a/3546/9780593851098
14 Amazon, Apple Books, Barnes & Noble, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/0593955978?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593955970?at=10lIEQ, https://barnesandnoble.sjv.io/c/197432/1961179/22009?prodsku=9780593955970&u=https%3A%2F%2Fwww.barnesandnoble.com%2Fw%2Fthe-gate-of-the-feral-gods-matt-dinniman%2F1146460801%3Fean%3D9780593955970&intsrc=APIG_15890, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FTHE%2BGATE%2BOF%2BTHE%2BFERAL%2BGODS%2FMatt%2BDinniman%2F9780593955970, https://bookshop.org/a/3546/9780593955970
15                                                                                                                                                                                                                                                          Amazon, Apple Books, Books-A-Million, Bookshop.org, https://www.amazon.com/dp/B08V8877BY?tag=thenewyorktim-20, https://goto.applebooks.apple/9780593820247?at=10lIEQ, https://www.anrdoezrs.net/click-7990613-35140?url=https%3A%2F%2Fwww.booksamillion.com%2Fp%2FDungeon-Crawler-Carl%2FMatt-Dinniman%2F9780593820247, https://bookshop.org/a/3546/9780593820247

$results$corrections
list()

Data Cleaning Notes

The API response includes metadata and nested JSON fields. I extracted only the books portion from data$results, since this contains the actual records for each book. I then selected a smaller set of relevant variables for analysis, including rank, title, author, publisher, week_on_list, and rank_last_week.

For rank_last_week, missing values were interpreted as newly listed books. To make the visualization easier to read, these missing values were labeled as “NEW.

class(data$results)
[1] "list"
books <- as_tibble(data$results$books)
books |>
  select(title, author, publisher, rank, description)
# A tibble: 15 × 5
   title                            author           publisher  rank description
   <chr>                            <chr>            <chr>     <int> <chr>      
 1 JUDGE STONE                      Viola Davis and… Little, …     1 "Judge Mar…
 2 THE CORRESPONDENT                Virginia Evans   Crown         2 "Letters f…
 3 BLOODLUST                        Sandra Brown     Grand Ce…     3 "The mutua…
 4 MY HUSBAND'S WIFE                Alice Feeney     Pine & C…     4 "In an old…
 5 INNAMORATA                       Ava Reid         Del Rey       5 "Passion a…
 6 CARL'S DOOMSDAY SCENARIO         Matt Dinniman    Ace           6 "The secon…
 7 MOTHER OF DEATH AND DAWN         Carissa Broadbe… Bramble       7 "The third…
 8 KIN                              Tayari Jones     Knopf         8 "Vernice a…
 9 BETWEEN TWO FIRES                Christopher Bue… Tor Nigh…     9 "In 1348, …
10 THE DUNGEON ANARCHIST'S COOKBOOK Matt Dinniman    Ace          10 "The third…
11 THE WIDOW                        John Grisham     Doubleday    11 "When Simo…
12 ALCHEMISED                       SenLinYu         Del Rey      12 "After the…
13 THE CROSSROADS                   C.J. Box         Putnam       13 "The 26th …
14 THE GATE OF THE FERAL GODS       Matt Dinniman    Ace          14 "The fourt…
15 DUNGEON CRAWLER CARL             Matt Dinniman    Ace          15 "A Coast G…

Visualizing the rank of books

books_clean <- books |>
  select(rank, author, publisher, title ) |>
  arrange(rank)
ggplot(books_clean, aes(x = reorder(title, -rank), y = rank, fill = title)) +
  geom_col() +
  coord_flip() +
  geom_text(aes(label = rank), hjust = -0.2) +
  labs(
    title = "Rank of the Top Books Best Sellers",
    x = "Book Title",
    y = "Rank (1 = Best)"
  ) + theme(legend.position = "none")

Visualization

The book ranked number 1 on the current list is *JUDGE STONE*. This indicates that it is the top-ranked book on this week’s hardcover fiction best seller list, though this ranking alone does not fully explain the author’s overall quality or long-term success. Though honestly, rank can be slightly awkward as a bar height because smaller is better. A table may communicate it more cleanly.

Column cleaning for analyzing weeks on the list

books_clean <- books |>
  select(rank, title, author, publisher, weeks_on_list) |>
  arrange(rank)
ggplot(books_clean, aes(x = reorder(title, -rank), y = weeks_on_list, fill = title)) +
  geom_col() +
  coord_flip() +
  labs(title = "Weeks on List for Current NYT Hardcover Fiction Best Sellers",
       x = "Book Title",
       y = "Weeks on List") + theme (legend.position = "none")

analyzing books week on list

To visualize the books week on list ranking, I used a bar chart geom_col where each book’s position reflects how long the book has been on the list. Missing values were handled to represent newly listed books, ensuring a complete and interpretable visualization.

we can observe the book with the title ALCHEMISED being on the list for longer period of time, following THE WIDOW and THE CORRESPONDENT

we can conclude that while the number of weeks on the list reflects a book’s sustained popularity, it does not necessarily indicate that the book is currently the best-selling. The weekly rank provides a more accurate measure of current performance, whereas weeks on list captures long-term success and consistency in sales

Exploring the rank_last_week

books_clean_2 <- books |>
  select(rank, rank_last_week, title, author) |>
  mutate(
    rank_last_week_label = ifelse(is.na(rank_last_week), "NEW", as.character(rank_last_week)),
    rank_last_week = ifelse(is.na(rank_last_week), max(rank, na.rm = TRUE) + 1,rank_last_week)
    
  )
ggplot(books_clean_2, aes(x = reorder(title, rank_last_week), y = rank_last_week, fill = title)) +
  geom_col() +
  coord_flip() +
  geom_text(aes(label = rank_last_week_label), hjust = -0.2) +
  labs(
    title = "Rank Last Week for Current NYT Hardcover Fiction Best Sellers",
    x ="Book Title",
    y = "Rank in the past Week"
  ) + theme(legend.position = "none")

Visualization

To visualize last week’s rankings, I used a bar chart where each book’s position reflects its rank in the previous week. Since rankings are ordinal (with lower values indicating higher performance), the titles were reordered based on rank_last_week. Missing values were handled to represent newly listed books, ensuring a complete and interpretable visualization.

Conclusion

Using the New York Times Books API, I retrieved the current hardcover fiction best seller list and transformed the JSON response into a tidy data frame in R. The analysis showed the current top-ranked books, how long they have remained on the list, and how their rankings compare with the previous week. Current rank provides the strongest indicator of present best-selling performance, while weeks on list reflects longer-term popularity and consistency.