Skip to content

Instantly share code, notes, and snippets.

@shannonpileggi
Last active February 4, 2021 11:58
Show Gist options
  • Save shannonpileggi/5f2d4ccc591d8e2a2963303ee9ede1fc to your computer and use it in GitHub Desktop.
Save shannonpileggi/5f2d4ccc591d8e2a2963303ee9ede1fc to your computer and use it in GitHub Desktop.
HBCU tidytuesday adapted from Ijeamaka Anyene
---
title: "hbcus"
author: "Shannon Pileggi adapting from Ijeamaka Anyene"
date: "2/4/2021"
output: html_document
---
Conversation on twitter:
https://twitter.com/ijeamaka_a/status/1356809290468626434
Original tidytuesday submission:
https://github.com/Ijeamakaanyene/tidytuesday/blob/master/scripts/2021_04_hbcu.Rmd
Incomplete graphic - just exploring to see if I could recreate Ijeamaka's graphic w/ coord_polar.
```{r}
library(dplyr)
library(ggplot2)
library(tidyr)
library(ggtext)
```
```{r}
extrafont::loadfonts()
```
```{r}
hbcu_all <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-02/hbcu_all.csv') %>%
janitor::clean_names()
```
```{r}
hbcu_enrollment <- hbcu_all %>%
mutate(
perc_male = males / total_enrollment,
perc_female = females /total_enrollment
)
```
```{r}
hbcu_stack <- hbcu_enrollment %>%
dplyr::select(year, perc_male, perc_female) %>%
pivot_longer(
-year,
names_to = c("metric", "gender"),
names_sep = "_",
values_to = "percent"
)
```
```{r}
hbcu_colors <- c(
"male" = "#f2a70c",
"female" = "#007a4d"
)
```
```{r}
hbcu_stack %>%
ggplot(aes(x = year, y = percent, fill = gender)) +
geom_bar(position = "stack", stat = "identity", width = 0.3) +
theme_void() +
theme(plot.background = element_rect(fill = "black"),
plot.margin = margin(4, 4, 4, 4, unit = "pt"),
panel.background = element_rect(fill = "black"),
plot.caption = element_text(color = "white",
family = "Literata",
size = 7),
legend.position = "none"
) +
scale_fill_manual(values = hbcu_colors) +
# double length for semi-circle ----
xlim(c(1937, 2016)) +
# create donut ---
ylim(c(-0.5, 1.2)) +
geom_hline(yintercept = 0.5) +
coord_polar()
ggsave("2021_04_hbcus.png",
device = "png",
width = 10,
height = 8)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment