Loading packages & Data
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.3
## ✓ tidyr 1.0.0 ✓ stringr 1.4.0
## ✓ readr 1.1.1 ✓ forcats 0.3.0
## Warning: package 'tibble' was built under R version 3.5.2
## Warning: package 'tidyr' was built under R version 3.5.2
## Warning: package 'purrr' was built under R version 3.5.2
## Warning: package 'dplyr' was built under R version 3.5.2
## Warning: package 'stringr' was built under R version 3.5.2
## ── Conflicts ─────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(wesanderson)
library(ggtext)
useThanks<-read.csv("https://raw.githubusercontent.com/kitadasmalley/FA2020_DataViz/main/data/useThanks.csv", header=TRUE)
Research Question: Do people still celebrate friendsgiving the older they get?
First Draft
useThanks <- useThanks %>%
filter(age == "18 - 29" | age == "30 - 44" | age == "45 - 59" | age == "60+") %>%
filter(friendsgiving != "")
df <- useThanks %>%
group_by(age) %>%
count(gender, friendsgiving)
thanksgiving_palette <- c("#EBBA38","#A26B35")
df %>%
ggplot(., aes(age, n, fill = gender)) +
geom_col(position = "dodge") +
facet_wrap(.~friendsgiving, nrow = 1) +
scale_fill_manual(values = thanksgiving_palette)

Polished Version
# For some reason, when I knit the document the subtitles are slightly offset. When I write the code and plot it in R, they come out even. Just wanted to let you know when you view the submitted document
dft <- df
dft
## # A tibble: 16 x 4
## # Groups: age [4]
## age gender friendsgiving n
## <fct> <fct> <fct> <int>
## 1 18 - 29 Female No 68
## 2 18 - 29 Female Yes 34
## 3 18 - 29 Male No 42
## 4 18 - 29 Male Yes 41
## 5 30 - 44 Female No 79
## 6 30 - 44 Female Yes 48
## 7 30 - 44 Male No 69
## 8 30 - 44 Male Yes 39
## 9 45 - 59 Female No 108
## 10 45 - 59 Female Yes 34
## 11 45 - 59 Male No 101
## 12 45 - 59 Male Yes 26
## 13 60+ Female No 118
## 14 60+ Female Yes 26
## 15 60+ Male No 95
## 16 60+ Male Yes 19
gend <- c("Female",
"Female",
"Male",
"Male",
"Female",
"Female1",
"Male",
"Male",
"Female",
"Female",
"Male",
"Male",
"Female2",
"Female",
"Male",
"Male")
dft$gend <- gend
thanksgiving_highlight_palette <- c("#FBDF6E","#CC5012","#C1311C","#D7CE93")
dft %>%
ggplot(., aes(age, n, fill = gend)) +
geom_col(position = "dodge") +
facet_wrap(.~friendsgiving, nrow = 1) +
scale_fill_manual(values = thanksgiving_highlight_palette,
name = "Gender",
breaks = c("Female", "", "", "Male")) +
theme_minimal() +
scale_x_discrete() +
labs(title = "Less People Celebrate Friendsgiving As They Get Older",
subtitle = "Women in the 60+ age range have the highest 'no' count",
tags = "Women in the 30-44 age range have the highest 'yes' count",
x = "Age of Respondents",
y = "# of Respondents Celebrating") +
theme(plot.title = element_text(family = "serif", size = 16, face = "bold", hjust = 1),
plot.subtitle = element_text(family = "serif", size = 11, face = "bold.italic", color = "red", hjust = -0.25, vjust = 2),
axis.title.x = element_text(family = "serif", size = 11),
axis.text = element_text(family = "serif", size = 11),
axis.title.y = element_text(family = "serif", size = 11),
legend.text = element_text(family = "serif", size = 11),
legend.title = element_text(family = "serif", size = 12),
plot.tag.position = c(.304,.899),
plot.tag = element_text(family = "serif", size = 11, face = "bold.italic", color = "orange"),
plot.margin = margin(.2,1,0.2,1, "cm"),
strip.text.x = element_text(size = 13, vjust = -1))

What I wanted it to look like (using outside resources)
What I wanted to do but wasn’t sure how, was to create these texts as an annotation and move the texts to the right side of the plot (above the legend)
dft %>%
ggplot(., aes(age, n, fill = gend)) +
geom_col(position = "dodge") +
facet_wrap(.~friendsgiving, nrow = 1) +
scale_fill_manual(values = thanksgiving_highlight_palette,
name = "Gender",
breaks = c("Female", "", "", "Male")) +
theme_minimal() +
scale_x_discrete() +
labs(title = "Less People Celebrate Friendsgiving As They Get Older",
subtitle = "Women in the <b style='color:red'>60+ age range have the highest 'no' count</b>",
tags = "Women in the <b style='color:orange'>30-44 age range have the highest 'yes' count</b>",
x = "Age of Respondents",
y = "# of Respondents Celebrating") +
theme(plot.title = element_text(family = "serif",
size = 16,
face = "bold",
hjust = 1),
plot.subtitle = element_text(family = "serif",
size = 11,
face = "bold.italic",
hjust = -0.25,
vjust = 2),
axis.title.x = element_text(family = "serif", size = 11),
axis.text = element_text(family = "serif", size = 11),
axis.title.y = element_text(family = "serif", size = 11),
legend.text = element_text(family = "serif", size = 11),
legend.title = element_text(family = "serif", size = 12),
plot.tag.position = c(.31,.891),
plot.tag = element_text(family = "serif",
size = 11,
face = "bold.italic"),
plot.margin = margin(.2,1,0.2,1, "cm"),
strip.text.x = element_text(size = 13, vjust = -1)) +
theme(plot.subtitle = element_markdown(lineheight = 10),
plot.tag = element_markdown(lineheight = 2))
