Figure 1: Bump chart illustrating the ranking of U.S. National Parks over time (1904-2016) by the count of visitors. This chart highlights the top 5 national parks as of 2016, and shows their relative popularity over time.
1. Load Packages & Setup
Show code
if(!require("pacman"))install.packages("pacman")pacman::p_load(tidyverse,tidytuesdayR,dlookr,ggtext,gt,gtExtras, #for font awesome icons in gt tablesggbump,showtext,janitor, #for clean_names()scales,htmltools, #for tagList()glue,here,geomtextpath)font_add('fa-brands', 'fonts/Font Awesome 6 Brands-Regular-400.otf')sysfonts::font_add_google("Lato","lato")showtext::showtext_auto()showtext::showtext_opts(dpi=300)
my_theme<-theme( text =element_text(family ='lato'), plot.title =element_textbox_simple(color="black", face="bold", size=20, hjust=0), plot.subtitle =element_textbox_simple(color="black", size=12, hjust=0), axis.title =element_blank(), axis.text =element_blank(), axis.ticks =element_blank(), axis.line =element_blank(), plot.caption =element_textbox_simple(color="black", size=12), panel.background =element_blank(), panel.grid.major =element_blank(), panel.grid.minor =element_blank(), panel.border =element_blank(), legend.title=element_blank(), legend.text =element_text(color="black", size=12, hjust=0), legend.position ='top', strip.text =element_text(color="black", size=14))title<-tagList(p('Ranking of popularity of U.S. National Parks'))subtitle<-tagList(span('*by the number of visitors annually*'))caption<-paste0("<span style='font-family:lato;'>**Source**: TidyTuesday Week 38 (2019)</span><br>","<span style='font-family:fa-brands;'></span>","<span style='font-family:lato;'>@mickey.rafa</span>","<span style='font-family:lato;color:white;'>....</span>","<span style='font-family:fa-brands;'></span>","<span style='font-family:lato;color:white;'>.</span>","<span style='font-family:lato;'>mrafa3</span>")description_color<-'grey40'subtitle_2<-tagList(span('*by the number of visitors by decade*'))
6. Plot
For the first plot, I wanted to replicate the bump chart created by FiveThirtyEight, which shows the ranking of U.S. national parks by annual visitors.
I like this high-level plot, and I think it’s effective if you want to highlight individual parks (or show a top 5, as I’ve done), but there is plenty of noise. In the next plot, I aggregated visitors by decade, and I’m only showing parks that were in the top five in the first decade of the dataset or the last decade. This strips out the noise and shows some interesting changes in park rankings over time.
Show code
(plot_viz_decade_bump<-df_decade%>%filter(unit_name%in%c(top_1900s, top_2010s),decade>=1900)%>%ggplot(.,aes(x=decade, y=-rank_visitors_by_decade, col=unit_name))+geom_point(shape ='|', stroke =6)+geom_bump(linewidth =1)+ggrepel::geom_text_repel( data =df_decade%>%filter(decade==1900, unit_name%in%top_1900s),aes(label =paste('#',rank_visitors_by_decade, " ", parkname_full, sep ="")),#nudge_x = -1, hjust =1, size =4, direction ="y", fontface ='bold')+ggrepel::geom_text_repel( data =df_decade%>%filter(decade==2010, unit_name%in%top_2010s),aes(label =paste('#',rank_visitors_by_decade, " ", parkname_full, sep ="")), hjust =0, nudge_x =1, size =4, direction ="y", fontface ='bold')+geom_text( data =df_decade%>%filter(decade==2010, unit_name%in%c('Hot Springs National Park', 'Wind Cave National Park', 'Crater Lake National Park')),aes(label =paste('#',rank_visitors_by_decade, " ", parkname_full, sep ="")), hjust =0, nudge_x =1, size =4, fontface ='bold')+annotate('text', x =c(1898, 2012), y =c(5, 5), label =c('1900s', '2010s'), hjust =c(0, 1), vjust =1, size =6, fontface ='bold')+coord_cartesian(xlim =c(1860, 2070), ylim =c(-45, 10), expand =F)+#theme_void() + my_theme+theme(legend.position ='none', panel.grid.major.x =element_blank(), panel.grid.minor.x =element_blank(), text =element_text( color =description_color))+labs( title =title, subtitle =subtitle_2, caption =caption))
7. Save
Show code
# Save the plot as PNGggsave( filename =glue("tt_{tt_year}_{tt_week}.png"), plot =plot_viz_538, width =10, height =8, units ="in", dpi =320)# make thumbnail for pagemagick::image_read(glue("tt_{tt_year}_{tt_week}.png"))%>%magick::image_resize(geometry ="400")%>%magick::image_write(glue("tt_{tt_year}_{tt_week}_thumbnail.png"))