Ten tips for better text: Typography meets ggplot and friends

RLadies Rome | A code-along workshop

Author
Published

November 30, 2023

This workshop explores tips from the worlds of visual perception, design, and typography, to make text our dataviz text more engaging. We created a basic plot, added some meaningful colours, improved our text hierarchy and gave everything some space to breathe, before applying the same principles to tables and interactive plots.

Recording

Slides

Full interactive table code

bakeoff_data <- bakeoff::episodes %>%
  mutate(star_baker = case_when(is.na(sb_name) ~ winner_name,
                                TRUE ~ sb_name)) %>%
  select(series, episode, star_baker) %>%
  left_join(technicals) %>%
  left_join(bakeoff::ratings %>%
              select(series, episode, uk_airdate, viewers_7day)) %>%
  mutate(hosts = case_when(series < 8 ~ "Mel & Sue",
                           TRUE ~ "Noel & Co"))

tidied_data <- bakeoff_data %>%
  mutate(fill_colour = case_when(
    str_detect(hosts, "Mel") ~ "pink",
    str_detect(hosts, "Noel") ~ "#2d2b23")) %>%
  select(series, episode, technical_bake, star_baker, viewers_7day, uk_airdate, fill_colour, hosts) %>%
  rowwise() %>%
  mutate(viewers_7day = viewers_7day * 1000000,
         technical_bake = stringr::str_to_sentence(technical_bake)) 


reactable(tidied_data,
          theme = reactableTheme(
            color = "#200000",
            headerStyle = list(fontWeight = "bold",
                               color = "#4C3232",
                               fontSize = "11pt"),
            style = list(fontFamily = "Cabin",
                         fontSize = "10pt"),
            highlightColor = "#f9f9f7",
            borderColor = "#E5E2E1",
          ),
          columns = list(
            series = colDef(name = "Series", 
                            align = "center",
                            maxWidth = 100,
                            minWidth = 100),
            episode = colDef(name = "Episode",
                             align = "center",
                             maxWidth = 100,
                             minWidth = 100),
            star_baker = colDef(name = "Star baker"),
            technical_bake = colDef(name = "Technical challenge",
                                    style = list(whiteSpace = "nowrap"),
                                    maxWidth = 375,
                                    minWidth = 375),
            uk_airdate = colDef(name = "UK air date",
                                format = colFormat(date = TRUE, locales = "en-GB"),
                                style = list(fontFamily = "Ubuntu Mono"),
                                maxWidth = 100,
                                minWidth = 100),
            viewers_7day = colDef(name = "Viewers within 7 days",
                                  minWidth = 150,
                                  align =  "left",
                                  cell = reactablefmtr::data_bars(tidied_data,
                                                                  text_color = "#200000",
                                                                  fill_color_ref = "fill_colour", 
                                                                  text_position = "outside-end",
                                                                  background = "#E9E6E5",
                                                                  number_fmt = function(x) grkmisc::pretty_num(x))),
            hosts = colDef(name = "Hosts",
                           maxWidth = 100,
                           minWidth = 100, 
                           show = FALSE),
            fill_colour = colDef(show = FALSE)
          ),
          highlight = TRUE
)

Reuse

Citation

For attribution, please cite this work as:
Thompson, Cara. 2023. “Ten Tips for Better Text: Typography Meets Ggplot and Friends.” November 30, 2023. https://www.cararthompson.com/talks/rladiesrome-ten-tips-for-better-dataviz-text.