Star Trek Timelines

Welcome to #TidyTuesday 2022 day 52

Networks
Published

December 27, 2022

Load the libraries

library(tidyverse)
tuesdata <- tidytuesdayR::tt_load(2022, week = 52)
tlBooks <- tuesdata$tlBooks
tlFootnotes<-tuesdata$tlFootnotes
tlBooks%>%names
tlFootnotes%>%names

Join the two sets by footnote

The new dataset combines, year, title, … with the footnote of the Star Trek Timelines. The data comes from the {rtrek} package by Georgios Karamanis.

df <- tlBooks %>%
  inner_join(tlFootnotes,by="footnote")

df%>%DataExplorer::profile_missing()%>%arrange(pct_missing)

How to make a Waffle

This is a little example from: https://r-charts.com/part-whole/waffle-chart-ggplot2/

# install.packages("waffle", repos = "https://cinc.rud.is")
library(waffle)

# Vector
x <- c(30, 25, 20, 5)

# Waffle chart
waffle(x, rows = 8)

In this dataset there are three formats: book, episode and story

df%>%
  count(format)%>%
  waffle(rows=20)

Using ggplot2

This Waffle is made of 12 different colors for identifying the SSeries. Here are used many colors from the trekcolors package for coloring the series of different colors.

# install.packages("trekcolors")
library(trekcolors)
# trekcolors::lcars_colors()

The fonts are from the trekfont package.

# install.packages("trekfont")
library(trekfont)
# trekfont::show_trekfonts()
library(showtext)
font <- c("Khan", "StarNext", "FederationDS9Title", "Federation", "Klingon", "ModernVulcan", "TNGcast", "FederationStarfleet")
path <- system.file(paste0("fonts/", font, ".ttf"), package = "trekfont")
for(i in seq_along(font)) font_add(font[i], path[i])
font_families()
showtext_auto(enable = TRUE)
library(waffle)
df%>%
  count(series)%>%
  drop_na()%>%
  waffle(rows = 20, size = 0.5)+
  scale_fill_manual(values =as.character(lcars_colors())) +
  # Waffle plot
  #ggplot(aes(fill = series, values = n)) +
  #geom_waffle(n_rows = 20, size = 0.5, colour = "white") +
  #scale_fill_manual(values =as.character(lcars_colors())) +
  coord_equal() +
  scale_x_continuous(expand = c(0, 0))+
  labs(title="Star Trek Timelines Series",
       subtitle = "",
       caption="DataSource: #TidyTuesday 2022 week52 - Star Trek Timelines\nDataViz: Federica Gazzelloni #30DayChartChallenge 2023 Day2 - Waffle\n")+
  theme_void()+
  theme(text = element_text(family= "StarNext",size=14),
        #legend.position = "bottom",
        plot.title = element_text(size=50,hjust = 0.3,vjust = 0),
        plot.caption = element_text(size=20,hjust = 0.4,family="FederationDS9Title"),
        panel.background = element_rect(fill="#9977AA",color="#9977AA"),
        plot.background = element_rect(fill="#9977AA",color="#9977AA"))
ggsave("ss.png",
       width = 6,height = 5.5,
       bg="#9977AA",
       dpi=200)