-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathFIG0219.R
66 lines (58 loc) · 2.02 KB
/
FIG0219.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
rm(list = ls())
library(tidyverse)
library(ggtext)
library(lemon)
source("helper_functions.R")
source("theme/theme_swd.R")
theme_set(theme_swd() + theme(
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_text(color = GRAY3, size = 8),
panel.border = element_blank(),
axis.line = element_line(),
axis.title.x = element_text(hjust = 0.03, color = GRAY6),
plot.subtitle = element_markdown(hjust = 0.65),
axis.line.y = element_blank()
))
df <- read_csv(file.path("data", "FIG0219.csv")) %>%
select(-Total) %>%
rename(Item = `X1`) %>%
pivot_longer(cols = -Item, names_to = "Answer", values_to = "Value") %>%
mutate(
Answer = factor(Answer, levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")),
Value = parse_number(Value) / 100
)
df$Answer <- fct_rev(df$Answer)
levels(df$Answer)
color_scale <- c(
"Strongly Disagree" = GRAY2,
"Disagree" = GRAY2,
"Neutral" = GRAY9,
"Agree" = BLUE5,
"Strongly Agree" = BLUE5)
formatted_subtitle <- paste0(
"<span style='color:", color_scale[1], "'>**", names(color_scale)[1], "**</span>",
" | ",
"<span style='color:", color_scale[2], "'>**", names(color_scale)[2], "**</span>",
" | ",
"<span style='color:", color_scale[3], "'>**", names(color_scale)[3], "**</span>",
" | ",
"<span style='color:", color_scale[4], "'>**", names(color_scale)[4], "**</span>",
" | ",
"<span style='color:", color_scale[5], "'>**", names(color_scale)[5], "**</span>"
)
pt <- df %>%
ggplot(aes(y = fct_rev(Item), x = Value, fill = Answer)) +
geom_bar(stat = "Identity", width = 0.65, color = "white") +
scale_fill_manual(values = color_scale, guide = F) +
labs(
title = "Survey Results",
subtitle = formatted_subtitle,
x = "Percent of total"
) +
scale_x_continuous(position = "top",
breaks = seq(0,1,by = 0.2),
labels = scales::percent_format(accuracy = 1)) +
coord_capped_cart(top = "both")
pt %>%
save_and_show_plot(width = 6, height = 4, "FIG0219.png")