library(tidyverse)
Load the libraries
<- tidytuesdayR::tt_load(2022, week = 52)
tuesdata <- tuesdata$tlBooks
tlBooks <-tuesdata$tlFootnotes tlFootnotes
%>%names tlBooks
%>%names tlFootnotes
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.
<- tlBooks %>%
df inner_join(tlFootnotes,by="footnote")
%>%DataExplorer::profile_missing()%>%arrange(pct_missing) df
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
<- c(30, 25, 20, 5)
x
# Waffle chart
waffle(x, rows = 8)
In this dataset there are three formats: book, episode and story
%>%
dfcount(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)
<- c("Khan", "StarNext", "FederationDS9Title", "Federation", "Klingon", "ModernVulcan", "TNGcast", "FederationStarfleet")
font <- system.file(paste0("fonts/", font, ".ttf"), package = "trekfont")
path for(i in seq_along(font)) font_add(font[i], path[i])
font_families()
showtext_auto(enable = TRUE)
library(waffle)
%>%
dfcount(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)