Files can be found here: https://drive.google.com/drive/folders/1wZPikIrge0GXmbHcdnl5qF4Qbuvz7dS5
ggplot_nicar_2024.Rmd has the instructions to work through. This is mostly to serve as a reminder because I think the easiest way to learn about these functions is by running it in R. I would look at that for examples or clarification if you aren’t sure how to use any of these.
To install fonts, for me they had to be a .ttf file but I could just change the extension from .otf to .ttf and had no problem. Open those files and install them.
To add text to the graph use labs. It can be either set equal to a string directly or to a string that was previously declared.
labs(title = title, subtitle = subtitle, caption = caption)
Use theme() which has many arguments. To format specific pieces of text, use plot.subtitle or replace subtitle with whichever part you are trying to format.
Set that equal to element_textbox_simple() which has arguments for family, color, size, and margin. Family is a string for the font you want to use. Margin is set equal to something like this: margin(5,0,8,0)
If you want to format specific words in text differently, you can style it with html:
subtitle <- "Almost every <span style='color:#4e3cc2; font-weight:bold; font-family:chartheader'>summer</span> since 2018, youth under 30 have made up a smaller percentage of shooting victims than during the previous <span style='color:#9491a7; font-weight: bold; font-family:chartheader;'>school year</span>."
geom_text(aes(label = percent(value, scale = 1, accuracy = .1)), position = position_dodge(width = .9), vjust = 1.6, color = "white", size = 3.0)
Value is the name of the column you want to label it with.
Position is set equal to position_dodge because in the geom_bar, the position element is also set to position_dodge().
Use these elements within the theme() block.
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line(size=.1, color = "black", linetype = "dotted")