The data this week are set up to recreate some of the beautiful visualizations made by W.E.B. DuBois who was, among many other things, a civil rights activist and data viz pioneer.
The data were compiled by Anthony Starks, Allen Hillery Sekou Tyler. Note that Anthony Starks has provided many examples and data preparation, including a “style guide” and article.
To get the data (and the viz!) I used:
svn checkout https://github.com/ajstarks/dubois-data-portraits/trunk/challenge/2022/challenge07
and then moved the files related to Challenge07 into this week’s folder.
data <- read_csv("challenge07/data.csv")
females <- read_csv("challenge07/females.csv")
males <- read_csv("challenge07/males.csv")
I’m going to start by flipping the x and y axes, and also use only the females.
all_tidy <- data %>%
pivot_longer(cols = c("Widowed", "Married", "Single"), names_to = "status",
values_to = "count") %>%
mutate(status = factor(status, levels = c("Widowed", "Married", "Single"))) %>%
mutate(`PER CENTS.` = ifelse(Gender == "Male", -count, count))
guide_axis_label_trans <- function(label_trans = identity, ...) {
axis_guide <- guide_axis(...)
axis_guide$label_trans <- rlang::as_function(label_trans)
class(axis_guide) <- c("guide_axis_trans", class(axis_guide))
axis_guide
}
guide_train.guide_axis_trans <- function(x, ...) {
trained <- NextMethod()
trained$key$.label <- x$label_trans(trained$key$.label)
trained
}
all_tidy %>%
ggplot(aes(x = Group, y = `PER CENTS.`, fill = status)) +
geom_bar(stat = "identity", width = 1) +
scale_fill_manual(values = c("#06b48b", "#D5174e", "#0343df")) +
scale_y_continuous(labels = abs, limits = c(-100,100)) +
coord_flip() +
theme_minimal() +
theme(legend.position = "none") +
xlab("") +
ggtitle("AGES.") +
geom_vline(xintercept = seq(0.5,9.5,1), color = "black", size = 0.1) +
geom_hline(yintercept = seq(-100, 100, by = 1), color = "black",
size = 0.1) #+
#guides(x.sec = guide_axis_label_trans(~.x))
praise()
## [1] "You are unreal!"