Code
library(tidyverse)
library(gt)
library(gtExtras)
This Quarto document contains a table built in R using {gt} and {gtExtras} packages for the R Studio 2022 Table Contest submission.
The table was created for #TidyTuesday week 19 NYTimes best sellers, shared on Twitter and Github on May 10, 2022. The table shows 21 titles with 80 or more total weeks on The New York Times’ fiction bestseller list between 1931 and 2020, arranged in descending order of total weeks appeared. Data from Post45 Data, credits to Sara Stoudt.
library(tidyverse)
library(gt)
library(gtExtras)
<- readr::read_tsv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-10/nyt_titles.tsv')
nyt_titles <- readr::read_tsv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-10/nyt_full.tsv') nyt_full
= nyt_titles %>% slice_max(total_weeks, n=20) %>%
df1 mutate(title=str_to_title(title))
= nyt_full %>% filter(title_id %in% df1$id) %>%
df2 mutate(rank=-1*rank) %>%
group_by(id=title_id) %>%
arrange(week) %>%
summarise(timeline=list(rank),.groups="drop")
= df1 %>% left_join(df2, by="id") df3
# replaced gt_sparkline() with gt_plt_sparkline() in gtExtras version 0.4.4.9000
# amended title
%>%
df3 select(-id) %>%
mutate(wk = total_weeks) %>%
relocate(wk,.after=total_weeks) %>%
gt() %>%
gt_theme_nytimes() %>%
#gt_sparkline(timeline, label=F, range_colors = c("#7014f2", "#06b178"))
gt_plt_sparkline(timeline, label=F, palette = c("black", "black", "#7014f2", "#06b178", "lightgrey")) %>%
gt_plt_bar_pct(wk, fill="#ffc300") %>%
cols_width(wk~px(100),
~px(100)) %>%
first_weekcols_align(align="right", columns=first_week) %>%
cols_label(total_weeks="total weeks",
first_week="first week",
debut_rank="debut rank",
best_rank="best rank",
wk="") %>%
tab_header(title="NY Times bestsellers",
subtitle=md("List of titles with more than 80 total weeks on the ***The New York Times***' fiction bestseller list between 1931 and 2020, arranged in descending order of total weeks.")) %>%
tab_source_note("#TidyTuesday week 19 | Data from Post45 Data by way of Sara Stoudt") %>%
tab_style(style = list(cell_text(style = "italic", color="black")),
locations = cells_body(columns = title))
NY Times bestsellers | ||||||||
List of titles with more than 80 total weeks on the The New York Times' fiction bestseller list between 1931 and 2020, arranged in descending order of total weeks. | ||||||||
title | author | year | total weeks | first week | debut rank | best rank | timeline | |
---|---|---|---|---|---|---|---|---|
Oh, The Places You'll Go! | Dr. Seuss | 1990 | 178 | 1990-02-25 | 14 | 1 | ||
The Celestine Prophecy | James Redfield | 1994 | 165 | 1994-03-06 | 10 | 1 | ||
The Da Vinci Code | Dan Brown | 2003 | 165 | 2003-04-06 | 9 | 1 | ||
The Bridges Of Madison County | Robert James Waller | 1992 | 164 | 1992-08-16 | 7 | 1 | ||
All The Light We Cannot See | Anthony Doerr | 2014 | 132 | 2014-05-25 | 2 | 1 | ||
The Caine Mutiny | Herman Wouk | 1951 | 123 | 1951-04-22 | 13 | 1 | ||
Where The Crawdads Sing | Delia Owens | 2018 | 114 | 2018-09-23 | 9 | 1 | ||
Auntie Mame | Patrick Dennis | 1955 | 112 | 1955-02-20 | 16 | 1 | ||
The Robe | Lloyd C. Douglas | 1942 | 111 | 1942-11-09 | 5 | 1 | ||
The Help | Kathryn Stockett | 2009 | 108 | 2009-03-29 | 15 | 1 | ||
Advise And Consent | Allen Drury | 1959 | 102 | 1959-08-16 | 13 | 1 | ||
The Five People You Meet In Heaven | Mitch Albom | 2003 | 100 | 2003-10-12 | 8 | 1 | ||
To Kill A Mockingbird | Harper Lee | 1960 | 98 | 1960-08-07 | 14 | 2 | ||
Hawaii | James A. Michener | 1959 | 94 | 1959-11-22 | 16 | 1 | ||
Anthony Adverse | Hervey Allen | 1933 | 86 | 1933-07-03 | 1 | 1 | ||
A Dance With Dragons | George R. R. Martin | 2011 | 86 | 2011-07-31 | 7 | 1 | ||
The Agony And The Ecstasy | Irving Stone | 1961 | 83 | 1961-04-02 | 11 | 1 | ||
Harry Potter And The Sorcerer's Stone | J. K. Rowling | 1998 | 82 | 1998-12-27 | 6 | 1 | ||
Gone Girl | Gillian Flynn | 2012 | 80 | 2012-06-24 | 9 | 1 | ||
Illusions | Richard Bach | 1977 | 80 | 1977-06-19 | 10 | 2 | ||
The Nightingale | Kristin Hannah | 2015 | 80 | 2015-02-22 | 2 | 3 | ||
#TidyTuesday week 19 | Data from Post45 Data by way of Sara Stoudt |