"

Visualising the NYT Bestsellers in this week’s #TidyTuesday

This week’s #r4ds #TidyTuesday is about the nytimes Bestsellers. I created some shelves containing the books that stayed on the list for at least 1 year. Which 4 books were there for 3+ yrs?
Author
Affiliation

Building Stories with Data

Published

May 12, 2022

{fig-alt=“A dataviz in the form of shelves with bars representing books. Each shelf spans two decades from 1930 to present. The text above the plot, formatted to resemble the opening pages of a novel reads: These shelves contain all the books which remained on the bestseller list for a year or more. They are arranged from left to right by debut week.

The longer a book was on the list, the thicker its spine. The closest it was to Number 1 on its debut week, the taller it is. The closest it got to Number 1, the more purple it is.

Most books on this list made it to Number 1 at some point. Different decades had different patterns, with more books in the 1950s-60s starting lower down on the list. Only one book in the 1980s remaining on the list for a year or more. The 1990s and early 2000s saw the longest residencies, with four books remaining on the bestseller list for more than three years.

Can you name them?” fig-align=“center”}

“These shelves cont

To get each shelf (facet) to span two decades, scales = "free_x" didn’t work because the data in the different decades had different ranges.

Instead, I created a custom function to feed into scales_x_date(), building on this solution by coolbutuseless: coolbutuseless.github.io/2019/03/07/custom-axis-breaks-on…

Code snippet in R showing a custom function, `limits_fun`, that defines date ranges for plotting data by decades from 1930 to 1969. The plot code applies `facet_wrap` and `scale_x_date` with free x-axis scaling. Code is displayed on a dark background for clarity.

# custom function
limits_fun <- function(x) {
  if (between(ymd(min(x)), ymd("1930-01-01"), ymd("1949-12-31"))) {
    c(ymd("1930-01-01"), ymd("1949-12-31"))
  } else if (between(ymd(min(x)), ymd("1950-01-01"), ymd("1969-12-31"))) {
    c(ymd("1950-01-01"), ymd("1969-12-31"))
  }
  # etc...
}

# plot code
plot +
  facet_wrap(~decades, ncol = 1, scales = "free_x") +
  scale_x_date(limits = limits_fun)

And here’s the making of!

Video

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2022. “Visualising the NYT Bestsellers in This Week’s #TidyTuesday.” May 12, 2022. https://www.cararthompson.com/posts/2022-05-12-this-weeks-r4ds-tidy-tuesday-is/.