Summary

The following document contains both the code and the plots of my final project, which aims to replicate six of Du Bois’ plots. This document does NOT provide detailed comments about the plot. To check that, please go over the scripts in the “challenge script” folder. Also, please check the “Read Me” document that contains detailed information about where to find the plots with a brief analysis, a reflection post plot-making, comparison with original plots, etc.

Note: All plot were made using only R.

Loading libraries

library(tidyverse)
library(readr)
library(janitor)
library(stats)
library(ggstance)
library(reprex)
library(ggrepel)
library(ggbrace)
library(grid)
library(jpeg)
library(showtext)

Du Bois Challenges

Challenge 1

#TIDYING DATA
challenge_1 <- read_csv("data/challenge data 1.csv")
challenge_1 <- clean_names(challenge_1)
challenge_1 <- challenge_1 %>%
  pivot_longer(cols = c(colored, white), 
               names_to = "category", 
               values_to = "percent")

#MAKING PLOT 
ggplot(data = challenge_1, 
       mapping = aes(x = percent, 
                     y = year, 
                     color = category, 
                     linetype = category)) +
  geom_path(size = 0.7) +
  scale_x_reverse(expand = c(0, 0), 
                  breaks = seq(100, 0, by = -5)) +
  scale_y_continuous(breaks = seq(1790, 1890, 10), 
                     expand = c(0, 0)) +
  scale_color_manual(name = NULL, 
                     labels = c(str_pad("= COLORED", 96, "right"), 
                                "= WHITE"),
                     values = c("black", 
                                "#8E8D8E")) +
  scale_linetype_manual(name = NULL, 
                        labels = c(str_pad("= COLORED", 96, "right"), 
                                                "= WHITE"), 
                        values = c("solid", "dashed")) +
  theme_minimal() +
  xlab(label = "\n PERCENT") +
  ggtitle("COMPARATIVE INCREASE OF WHITE AND COLORED\n POPULATION OF GEORGIA.") +
  theme(axis.ticks = element_blank(), 
        axis.title.y = element_blank(), 
        panel.grid.minor = element_blank(), 
        panel.grid.major = element_line(color = "red", 
                                        size = 0.2), 
        panel.border = element_rect(color = "black", 
                                    fill = NA, 
                                    size = 1), 
        plot.title = element_text(face = "bold", 
                                  hjust = .5, 
                                  size = 18), 
        axis.text.y = element_text(face = "bold", 
                                   colour = "#848484"), 
        axis.text.x = element_text(face = "bold", 
                                   color = "#848484"), 
        axis.title.x = element_text(face = "bold", 
                                    color = "#848484"), 
        legend.position = "bottom", 
        legend.key.width = unit(3, "cm"), 
        legend.text = element_text(face = "bold"),
        plot.margin = unit(c(1, 1, 1, 1),
                           "cm"),
        plot.background = element_rect(fill = "#E4D7C7"))




Challenge 2

#TIDYING DATA 
challenge_2 <- read_csv("data/challenge data 2.csv") 
challenge_2 <- clean_names(challenge_2)

challenge_2 <- challenge_2 %>%
  pivot_longer(cols = c(single, 
                        married,
                        divorced_and_widowed), 
               names_to = "status", 
               values_to = "number")

#PERCENT FUNCTION 
percent <- function(x) {
  paste0(x, "%")
}

#MAKING PLOT 1 
challenge_2_back <- ggplot(data = challenge_2,
                           mapping = aes(x = population,
                                         y = number,
                                         fill = status,
                                         label = percent(number))) +
  geom_col(key_glyph = draw_key_point, 
           width = 0.5)+
  geom_text(position = position_stack(vjust = 0.5), 

            mapping = aes(size = number)) +
  scale_size(range = c(2, 6), 
             guide = "none") +
  scale_x_discrete(limits = c("Negroes", 
                              "Germany"),
                   label = c("NEGROES", 
                             "GERMANY")) +
  scale_fill_manual(values = c("#377E22",
                               "#EACC45", 
                               "#CA3142"), 
                    name = NULL,
                    labels = c("WIDOWED AND DIVORCED", 
                               "MARRIED", 
                               str_pad("SINGLE", 
                                       50, 
                                       "right"))) +
  coord_flip()+
  facet_wrap(~age,
             nrow = 3) +
  theme_minimal() +
  ggtitle("CONJUGAL CONDITION") +
  theme(legend.position = "top", 
        axis.title = element_blank(), 
        panel.grid = element_blank(), 
        axis.text.x = element_blank(),
        strip.text = element_blank(),
        panel.spacing = unit(4, "lines"), 
        plot.title = element_text(face = "bold", 
                                  hjust = 0.5),
        plot.margin = unit(c(0.5, 1, 1, 4),
                           "cm"),
        plot.background = element_rect(fill = "#E4D7C7")) +
  guides(fill=guide_legend(ncol=2,
                           reverse = TRUE, 
                           override.aes = list(shape = 19, 
                                               size = 5, 
                                               color = c("#CA3142",
                                                         "#EACC45",
                                                         "#377E22"))))

#SAVING PLOT AS IMAGE 
ggsave(filename = "challenge_2_back.jpeg", 
       plot = challenge_2_back, 
       width = 8,
       height = 7, 
       units = "in")

#USING THE IMAGE AS BACKGROUND 
img.file <- rasterGrob(readJPEG(source = "challenge_2_back.jpeg"),
                       width = unit(1, "npc"), 
                       height = unit(1, "npc"))

challenge_2_background <- ggplot() +
  annotation_custom(
    grob = img.file,
    xmin = -Inf, xmax = Inf,
    ymin = -Inf, ymax = Inf
  ) 

#MAKING FINAL PLOT 
challenge_2_final <- challenge_2_background +
  annotate(geom = "segment", 
           x = 0, 
           xend = 0, 
           y = 418,
           yend = -52, 
           color = "transparent") +
  annotate(geom = "segment", 
           x = -250, 
           xend = 250, 
           y = 0,
           yend = 0, 
           color = "transparent") +
  ##adding text that outlines the age group
  annotate(geom= "text", 
           label = "60\nAND\nOVER", 
           x = -230, 
           y = 2, 
           size = 4) +
  annotate(geom= "text", 
           label = "40-60", 
           x = -230, 
           y = 156, 
           size = 4) +
  annotate(geom= "text", 
           label = "AGE\n15-40", 
           x = -230, 
           y = 305, 
           size = 4) +
  #adding curly braces 
  geom_brace(mapping = aes(c(-200, -180), 
                           c(-25, 30)),
             rotate = 270,
             inherit.data=F) +
  geom_brace(mapping = aes(c(-200, -180), 
                           c(127, 182)),
             rotate = 270,
             inherit.data=F) +
  geom_brace(mapping = aes(c(-200, -180),
                           c(278, 333)),
             rotate = 270,
             inherit.data=F) +
  theme_void()

challenge_2_final

Challenge 3

#TIDYING DATA
challenge_3 <- read_csv("data/challenge data 3.csv")
challenge_3 <- clean_names(challenge_3)

challenge_3_dummy_1 <- data.frame("Negroes", "nothing", 70)
challenge_3_dummy_2 <- data.frame("Whites", "nothing", 70)
names(challenge_3_dummy_1) <- names(challenge_3)
names(challenge_3_dummy_2) <- names(challenge_3)

challenge_3_ready <- rbind(challenge_3, challenge_3_dummy_1)
challenge_3_ready <- rbind(challenge_3_ready, challenge_3_dummy_2)
challenge_3_ready <- challenge_3_ready %>%
  mutate(row = row_number()) 

challenge_3_ready$row <- factor(challenge_3_ready$row, 
                                levels = c(1, 3, 2, 5, 4, 11, 6, 8, 7, 10, 9, 12), 
                                ordered = TRUE)

#MAKING THE PLOT 1
challenge_3_back <- ggplot(data = challenge_3_ready, 
                           mapping = aes(x = "x", 
                                         y = percentage, 
                                         fill = occupation, 
                                         group = row)) +
  geom_bar(stat = "identity", 
           show.legend = FALSE) +
  scale_y_reverse() +
  scale_fill_manual(values = c("#D03F47", "#FACC37", "#7D8CB7", 
                               "#E1D8C9", "#BBA390", "#DED2BF")) +
  coord_polar("y", 
              start = 5.3, 
              direction = 1) +
  ggtitle("OCCUPATIONS OF NEGROES AND WHITES IN GEORGIA .") +
  theme_void() +
  theme(plot.title = element_text(face = "bold", 
                                  hjust = 0.5,
                                  family = "mono",
                                  vjust = -0.5), 
        plot.background = element_rect(fill = "#E1D8C9", 
                                       color = "transparent"))

#SAVING PLOT AS IMAGE 
ggsave(filename = "challenge_3_back.jpeg", 
       plot = challenge_3_back, 
       width = 6.5,
       height = 6.5, 
       units = "in")

img.file_3 <- rasterGrob(readJPEG(source = "challenge_3_back.jpeg"),
                         width = unit(1, "npc"), 
                         height = unit(1, "npc"))

#USING IMAGE AS BACKGROUND
challenge_3_background <- ggplot() +
  annotation_custom(grob = img.file_3,
                    xmin = -250, xmax = 250,
                    ymin = -52, ymax = 418) +
  coord_fixed() +
  xlim(250, -250) +
  ylim(-52, 418)

#MAKING PLOT 2
challenge_3_final_v1 <- challenge_3_background +
  geom_point(mapping = aes(x = 150,
                           y = 200), 
             size = 10, 
             shape = 21, 
             fill = "#D03F47", 
             color = "black") +
  geom_point(mapping = aes(x = 150,
                           y = 160), 
             size = 10, 
             shape = 21, 
             fill = "#7D8CB7", 
             color = "black") +
  geom_text(label = "AGRICULTURE, FISHERES\nAND MINING.", 
            mapping = aes(x = 105,
                          y = 200, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0.5, 
            size = 2) +
  geom_text(label = "MANUFACTURING AND \nMECHANICAL INDUSTRIES.", 
            mapping = aes(x = 135, 
                          y = 160, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0, 
            size = 2) +
  geom_point(mapping = aes(x = -150,
                           y = 175), 
             size = 10, 
             shape = 21, 
             fill = "#BBA390", 
             color = "black") +
  geom_point(mapping = aes(x = -150,
                           y = 215), 
             size = 10, 
             shape = 21, 
             fill = "#FACC37", 
             color = "black") +
  geom_point(mapping = aes(x = -150,
                           y = 135), 
             size = 10, 
             shape = 21, 
             fill = "#E1D8C9", 
             color = "black") +
  geom_text(label = "DOMESTIC AND \n PERSONAL SERVICE.", 
            mapping = aes(x = -105, 
                          y = 215, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0.5, 
            size = 2) +
  geom_text(label = "PROFESSIONS.", 
            mapping = aes(x = -115,
                          y = 175, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0.5, 
            size = 2) +
  geom_text(label = "TRADE AND\nTRANSPORTATION.", 
            color = "#847B6F",
            mapping = aes(x = -110, 
                          y = 135, 
                          family = "mono"),
            hjust = 0.5, 
            size = 2) +
  theme(plot.background = element_rect(fill = "#DBCFBD")) +
  theme_void()

#MAKING PLOT FINAL
challenge_3_final_v1 +
  geom_text(label = "62%", 
            mapping = aes(x = 50, 
                          y = 320, 
                          family = "mono"),
            hjust = 0.5, 
            size = 4) +
  geom_text(label = "28%", 
            mapping = aes(x = -70, 
                          y = 322, 
                          family = "mono"),
            hjust = 0.5, 
            size = 4) +
  geom_text(label = "5%", 
            mapping = aes(x = -114, 
                          y = 297, 
                          family = "mono"),
            hjust = 0.5, 
            size = 3) +
  geom_text(label = "4.5%", 
            mapping = aes(x = -129,
                          y = 290, 
                          family = "mono"),
            hjust = 0.5, 
            size = 2.5) +
  geom_text(label = ".5%", 
            mapping = aes(x = -136, 
                          y = 285, 
                          family = "mono"),
            hjust = 0.5, 
            size = 1) +
  geom_text(label = "4%", 
            mapping = aes(x = 135,
                          y = 60, 
                          family = "mono"),
            hjust = 0.5, 
            size = 3) +
  geom_text(label = "13%", 
            mapping = aes(x = 110, 
                          y = 45, 
                          family = "mono"),
            hjust = 0.5, 
            size = 3) +
  geom_text(label = "13.5%", 
            mapping = aes(x = 80, 
                          y = 22, 
                          family = "mono"),
            hjust = 0.5, 
            size = 3) +
  geom_text(label = "5.5%", 
            mapping = aes(x = 45,
                          y = 6, 
                          family = "mono"),
            hjust = 0.5, 
            size = 2.5) +
  geom_text(label = "64%", 
            mapping = aes(x = -50,
                          y = 30, 
                          family = "mono"),
            hjust = 0.5, 
            size = 4) +
  geom_text(label = "NEGROES.", 
            mapping = aes(x = 0, 
                          y = 365, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0.5, 
            size = 5) +
  geom_text(label = "WHITES. ", 
            mapping = aes(x = 0, 
                          y = -15, 
                          family = "mono"),
            color = "#847B6F",
            hjust = 0.5, 
            size = 5) 

Challenge 4

#GETTING SPECIAL FONTS
font_add_google("Goldman", "goldman")

#TIDYING DATA
challenge_4 <- read_csv("data/challenge data 4.csv")
challenge_4 <- clean_names(challenge_4)
challenge_4 <- challenge_4 %>%
  mutate(percent = paste0(free, "%")) %>%
  mutate(percent = ifelse(percent == "100%", 
                          "", 
                          percent))

#TEXT ANNOTATIONS
grob <- grobTree(textGrob("100%", 
                          x = 1,  
                          y = 0.915, 
                          hjust = 0.5,
                          gp = gpar(fontsize = 11, 
                                    fontfamily = "sans", 
                                    fontface = "bold")))

grob1 <- grobTree(textGrob("SLAVES\nESCLAVES", 
                           x = 0.5,  
                           y = 0.5, 
                           hjust = 0.5,
                           gp = gpar(fontsize = 20, 
                                     fontfamily = "goldman", 
                                     col = "#DFD6CB")))

grob2 <- grobTree(textGrob("FREE - LIBRE", 
                           x = 0.5,  
                           y = 0.95, 
                           hjust = 0.5,
                           gp = gpar(fontsize = 20, 
                                     fontfamily = "goldman", 
                                     col = "black")))

#ACTIVATING SPECIAL FONT
showtext_auto()

#MAKING THE PLOT
ggplot(data = challenge_4, 
       mapping = aes(x = year, 
                     y = free,
                     label = percent)) +
  geom_line() +
  geom_area(fill = "#4E875D") +
  scale_y_reverse(expand = c(0, 0)) +
  scale_x_continuous(position = "top", 
                     breaks = seq(1790, 1870, 10), 
                     expand = c(0,0)) +
  coord_cartesian(clip = "off") +
  geom_text(vjust = -0.5, 
            fontface = "bold", 
            family = "sans") +
  ggtitle(label = "PROPORTION OF FREEMEN AND SLAVES AMONG AMERICAN NEGROES .\n
          PROPORTION DES NÈGRES AT DES ESCLAVES EN AMÉRIQUE .\n", 
          subtitle = "DONE BY ATLANTA UNIVERSITY .\n\n\n\n\n\n") +
  theme(axis.ticks = element_blank(), 
        axis.title = element_blank(),
        axis.text.y = element_blank(), 
        panel.background = element_rect(fill = "black"), 
        panel.grid = element_blank(), 
        plot.margin = unit(c(1, 1, 1, 1),
                           "cm"), 
        plot.background = element_rect(fill = "#DFD6CB"), 
        axis.text.x = element_text(face = "bold", 
                                   color = "black", 
                                   size = 10, 
                                   family = "goldman"), 
        plot.title = element_text(family = "goldman",
                                  hjust = 0.5, 
                                  face = "bold"), 
        plot.subtitle = element_text(family = "goldman", 
                                     size = 8,
                                     hjust = 0.5, 
                                     face = "bold")) +
  annotation_custom(grob) +
  annotation_custom(grob1) +
  annotation_custom(grob2)

Challenge 7

#TIDYING DATA 
#for the spiral
challenge_7 <- read_csv("data/challenge data 7.csv")
challenge_7 <- clean_names(challenge_7)

max_val <- max(challenge_7$houshold_value_dollars)
max_val <- max_val/1.8
max_val_2 <- max_val*2

challenge_7_1 <- c(2021, max_val_2)
challenge_7 <- rbind(challenge_7, challenge_7_1)

gradient <- (7 - -1) / (0 - max_val)

challenge_7_plot <- challenge_7 %>%
  mutate(year = as.factor(year),
         y = seq(10, 
                 by = -1.5,
                 length.out = 7),
         x = 0) %>%
  rowwise() %>%
  mutate(xend = min(houshold_value_dollars, max_val),
         yend = gradient*xend + y) %>%
  mutate(y2 = yend,
         x2 = 0, 
         x2_end = ifelse(houshold_value_dollars < max_val, 
                         NaN, 
                         houshold_value_dollars - max_val),
         y2_end = gradient*x2_end + y2)
 
#for spiral borders     
challenge_border <- challenge_7_plot
challenge_border
row_to_keep = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)
challenge_border <- challenge_border[row_to_keep,]
challenge_border
#GETTING FONTS
font_add_google("Chakra Petch", "Chakra Petch")
showtext_auto()

#MAKING PLOT 1
challenge_7_back <- ggplot(data = challenge_7_plot) +
  geom_segment(data = challenge_border, 
               aes(x = x,
                   y = y, 
                   xend = xend, 
                   yend = yend), 
               color = "black",
               size = 5) +
  geom_segment(aes(x = x,
                   y = y, 
                   xend = xend, 
                   yend = yend,
                   color = year), 
               size = 4,
               show.legend = FALSE) +
  geom_segment(data = challenge_border,
               aes(x = x2, 
                   y = y2, 
                   xend = x2_end,
                   yend = y2_end),
               color = "black",
               size = 5) +
  geom_segment(aes(x = x2, 
                   y = y2, 
                   xend = x2_end,
                   yend = y2_end, 
                   color = year), 
               size = 4, 
               show.legend = FALSE) +
  
  scale_color_manual(values = c("#DCAAA0", "#A6A3B2", "#BCA38D", 
                                "#E7B257", "light gray", "#C9444E", 
                                "transparent")) +
  coord_polar() +
  ggtitle("ASSESSED VALUE OF HOUSEHOLD AND KITCHEN FURNITURE\nOWNED BY GEORGIA NEGROES") +
  theme_void() +
  theme(plot.background = element_rect(fill = "#E4D7C7",
                                       color = NA), 
        plot.margin = unit(c(1, 0.5, 0, 0.5), 
                           "cm"), 
        plot.title = element_text(hjust = 0.5, 
                                  family = "Chakra Petch", 
                                  face = "bold", 
                                  size = 12)) 

#SAVING IMAGE
ggsave(filename = "challenge_7_back.jpeg", 
       plot = challenge_7_back, 
       width = 6,
       height = 6, 
       units = "in")

img.file <- rasterGrob(readJPEG(source = "challenge_7_back.jpeg"),
                       width = unit(1, "npc"), 
                       height = unit(1, "npc"))

#USING IMAGE AS BACKGROUND
challenge_7_background <- ggplot() +
  annotation_custom(
    grob = img.file,
    xmin = -Inf, xmax = Inf,
    ymin = -Inf, ymax = Inf
  )

#MAKING FINAL PLOT
challenge_7_background +
  annotate(geom = "segment", 
           x = 0, 
           xend = 0, 
           y = 418,
           yend = -52, 
           color = "transparent") +
  annotate(geom = "segment", 
           x = -250, 
           xend = 250, 
           y = 0,
           yend = 0, 
           color = "transparent") +
  annotate(geom = "segment", 
           x = 0, 
           xend = 0, 
           y = 269,
           yend = 334, 
           color = "black") +
  annotate(geom = "text", 
           label = "1875            $   21,186", 
           x = -123, 
           y = 327, 
           hjust = 0) +
  annotate(geom = "text", 
           label = "1880          $   498,532", 
           x = -123, 
           y = 316, 
           hjust = 0) +
  annotate(geom = "text", 
           label = "1885          ''    763,170", 
           x = -123, 
           y = 305, 
           hjust = 0) +
  annotate(geom = "text", 
           label = "1890          '' 1,173,624", 
           x = -123, 
           y = 294, 
           hjust = 0) +
  annotate(geom = "text", 
           label = "1895          '' 1,322,694", 
           x = -123, 
           y = 283, 
           hjust = 0) +
  annotate(geom = "text", 
           label = "1899          '' 1,434,975", 
           x = -123, 
           y = 272, 
           hjust = 0) +
  theme(axis.text = element_blank(), 
        axis.ticks = element_blank(), 
        axis.title = element_blank())

Challenge 10

#GETTING SPECIAL FONTS 
font_add_google("Goldman", "goldman")

#TIDYING DATA
#there is no dataset for this challenge
#I have been looking for it online, however, 
#a lot of the online pages say that such records were lost due to the fire of 1921
#therefore, I will replicate the data set from the original plot 

#SETUP GA MAP DATA
GA_map_data <- tigris::counties(state = "ga", cb = TRUE)

GA_map_data <- clean_names(GA_map_data) %>%
  select(c(name, geometry)) %>%
  mutate(county = name) 

GA_map_data$name <- NULL

#ADDING RELEVANT VARIABLE TO REPLICATE PLOT
#I made the following csv 
population_data <- read_csv("data/challenge_10_support_data.csv")
population_data <- clean_names(population_data)

challenge_10_data <- merge(GA_map_data, population_data, "county")
challenge_10_data$population <- factor(challenge_10_data$population, 
                                       levels = c("black", "dark blue", "brown", "gray",
                                                  "red", "pink", "yellow", "green"))
#ACTIVATING SPECIAL FONT 
showtext_auto()

#MAKING THE PLOT
ggplot(data = challenge_10_data, 
       mapping = aes(geometry = geometry,
                     fill = population)) +
         geom_sf(color = "black", 
                 key_glyph = draw_key_point) +
  scale_fill_manual(name = NULL,
                    values = c("black", "#242667", "#593A2B", "#C9B39E",
                                "#C83A4D", "#E0B1AB", "#ECC079", "#3C4F42"), 
                    label = c(str_pad("OVER 30.000 NEGROES", width = 40, side = "right"), 
                              "BETWEEN 20.000 AND 30.000",
                              "15.000 TO 20.000", "10.000 TO 15.000",
                              "5.000 TO 10.000", "2.500 TO 5.000",
                              "1.000 TO 2.500", "UNDER 1.000")) +
  theme_void() +
  ggtitle(label = "NEGRO POPULATION OF GEORGIA BY COUNTIES.", 
          subtitle = "1890.\n\n\n\n\n\n") +
  theme(plot.background = element_rect(fill = "#E2D4C6"),
        plot.title = element_text(hjust = 0.5, 
                                  vjust = 0.5, 
                                  family = "goldman"), 
        plot.subtitle = element_text(hjust = 0.5, 
                                     family = "goldman"), 
        legend.position = "bottom", 
        plot.margin = unit(c(1, 3, 1, 3),
                           "cm"), 
        legend.text = element_text(family = "mono")) +
  guides(fill= guide_legend(ncol = 2,
                            override.aes = list(shape = 21, 
                                                size = 8)))