Historical trend in the number of democratic versus non-democratic countries, illustrating the growth of democracies and the decline of non-democracies over time
#TidyTuesday
Author
Steven Ponce
Published
November 3, 2024
Steps to Create this Graphic
1. Load Packages & Setup
Show code
## 1. LOAD PACKAGES & SETUP ----if (!require("pacman")) install.packages("pacman")pacman::p_load( tidyverse, # Easily Install and Load the 'Tidyverse' ggtext, # Improved Text Rendering Support for 'ggplot2' showtext, # Using Fonts More Easily in R Graphs janitor, # Simple Tools for Examining and Cleaning Dirty Data scales, # Scale Functions for Visualization glue, # Interpreted String Literals here, # A Simpler Way to Find Your Files geomtextpath # Curved Text in 'ggplot2') ### |- figure size ----camcorder::gg_record(dir = here::here("temp_plots"),device ="png",width =10,height =8,units ="in",dpi =320)### |- resolution ----showtext_opts(dpi =320, regular.wt =300, bold.wt =800)
### |- tidy data ----# Line Plot of Democracy Count Over Time line_data <- democracy_data |>group_by(year) |>summarize(democratic_count =sum(is_democracy, na.rm =TRUE),non_democratic_count =sum(is_communist, na.rm =TRUE) ) |>ungroup()
5. Visualization Parameters
Show code
### |- plot aesthetics ----bkg_col <-"#f5f5f2"title_col <-"gray20"subtitle_col <-"gray20"caption_col <-"gray30"text_col <-"gray20"### |- titles and caption ----# iconstt <-str_glue("#TidyTuesday: { 2024 } Week { 45 } • Source: democracyData R Package<br>")li <-str_glue("<span style='font-family:fa6-brands'></span>")gh <-str_glue("<span style='font-family:fa6-brands'></span>")bs <-str_glue("<span style='font-family:fa6-brands'> </span>")# texttitle_text <-str_glue("Rise and Fall of Democracies and Non-Democracies (1950-2020)")subtitle_text <-str_wrap("Historical trend in the number of democratic versus non-democratic countries, illustrating the growth of democracies and the decline of non-democracies over time",width =85)caption_text <-str_glue("{tt} {li} stevenponce • {bs} sponce1 • {gh} poncest • #rstats #ggplot2")### |- fonts ----font_add('fa6-brands', here::here("fonts/6.6.0/Font Awesome 6 Brands-Regular-400.otf"))font_add_google("Oswald", regular.wt =400, family ="title")font_add_google("Merriweather Sans", regular.wt =400, family ="subtitle")font_add_google("Merriweather Sans", regular.wt =400, family ="text")font_add_google("Noto Sans", regular.wt =400, family ="caption")showtext_auto(enable =TRUE)### |- plot theme ----theme_set(theme_minimal(base_size =14, base_family ="text")) theme_update(plot.title.position ="plot",plot.caption.position ="plot",legend.position ="plot",plot.background =element_rect(fill = bkg_col, color = bkg_col),panel.background =element_rect(fill = bkg_col, color = bkg_col),plot.margin =margin(t =10, r =20, b =10, l =20),axis.title.x =element_text(margin =margin(10, 0, 0, 0), size =rel(1.1), color = text_col, family ="text", face ="bold", hjust =0.5),axis.title.y =element_text(margin =margin(0, 10, 0, 0), size =rel(1.1), color = text_col, family ="text", face ="bold", hjust =0.5),axis.text =element_text(size =rel(0.8), color = text_col, family ="text"),axis.ticks.x =element_line(color = text_col),axis.line.x =element_line(color ="#252525", linewidth = .2),panel.grid.minor =element_blank(),panel.grid.major =element_blank(),panel.grid.major.y =element_line(color ="grey85", size = .4),)