Created
May 2, 2025 01:07
-
-
Save MokeEire/e31ca34b79992df9ec1b6cd8f8027054 to your computer and use it in GitHub Desktop.
Cleaner bar chart for Nashville Poll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(showtext) | |
# Add fonts similar to those used on Vanderbilt's website | |
font_add_google("Arimo", "arimo") | |
font_add_google("Noto Serif Display", "noto-serif-display") | |
showtext_auto() | |
# Create dataframe with top priorities data | |
# From Slide 24: https://www.vanderbilt.edu/csdi/Nasville_2025_slides_final.pdf | |
top_priorities_df = tribble( | |
~priority, ~pct, | |
"Improving public education", .74, | |
"Working on problems low-income people face", .69, | |
"Making rents in Nashville more affordable", .67, | |
"Reducing crime", .64, | |
"Taking steps to ensure the city's long-term financial health", .62, | |
"Making home buying in Nashville more affordable", .61, | |
"Reducing traffic", .6, | |
"Dealing with homelessness", .55, | |
"Supporting small and local business", .49, | |
"Improving public transportation", .49 | |
) | |
# Plot | |
top_priorities_df |> | |
# Convert priority to factor ordered by % | |
mutate(priority = fct_reorder(priority, pct), | |
rank = rank(desc(pct))) |> | |
ggplot(aes(y = priority, x = pct)) + | |
# Highlight top 3 priorities (because too many priorities really means no priorities) | |
geom_col(aes(fill = rank <= 3), alpha=.95, width = .65, | |
show.legend=F) + | |
geom_text(aes(label = scales::percent(pct, accuracy = 1), | |
fontface = if_else(rank <= 3, "bold", "plain")), | |
colour = "white", | |
hjust = 1.2, | |
size = 8) + | |
scale_x_continuous(labels = scales::percent_format(accuracy = 1), | |
limits = c(0,1), position = "top") + | |
# Colour picked from Vanderbilt's logo | |
scale_fill_manual(values = c("TRUE" = "#bfa058", "FALSE" = "#555555")) + | |
labs( | |
title = "Top Priorities for Mayor Freddie O'Connell", | |
subtitle = "% Rated as Top Priority by Nashville residents", | |
y = NULL, | |
x = NULL, #"% rated as top priority", | |
caption = "Source: VU Nashville Poll (2025)" | |
) + | |
theme_minimal(base_family = "arimo")+ | |
# Text colours from vanderbilt.edu website | |
theme(plot.title.position = "plot", plot.margin = margin(20,20,20,20), | |
axis.text.y.left = element_text(size = 28, colour = "#1c1c1c", margin = margin(0,0,0,0)), | |
axis.text.x.top = element_text(colour = "#555555", size = 20), | |
axis.title.x.top = element_text(hjust = 1), | |
panel.grid.major.y = element_blank(), | |
panel.grid.minor = element_blank(), | |
plot.background = element_rect(fill = "#f5f3ef", colour = "#f5f3ef"), | |
plot.title = element_text(size = 56, face = "bold", margin = margin(5,0,5,0), | |
family = "playfair-display", colour = "#1c1c1c"), | |
plot.subtitle = element_text(size = 28, | |
family = "arimo", colour = "#555555"), | |
plot.caption = element_text(size = 20, margin = margin(20,0,0,0), | |
family = "arimo", colour = "#555555") | |
) | |
# Save as png | |
ggsave("top_priorities.png", width = 8, height = 4, dpi = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment