Code
# Data wrangling & visualization
library(tidyverse) # Data manipulation & visualization
# Spatial data handling
library(sf) # Import, export, and manipulate vector data
library(terra) # Import, export, and manipulate raster data
# ggplot2 extensions
library(tidyterra) # Helper functions for using terra with ggplot2
# Final plot tools
library(scales) # Nice Scales for ggplot2
library(fontawesome) # Icons display in ggplot2
library(ggtext) # Markdown text in ggplot2
library(showtext) # Display fonts in ggplot2
library(patchwork) # Composing Plots
= 42 # Base Text Size
bts ::font_add_google("Roboto Condensed", "body_font")
sysfonts::font_add_google("Oswald", "title_font")
sysfonts::font_add_google("Saira Extra Condensed", "caption_font")
sysfonts::showtext_auto()
showtext# A base Colour
<- "white"
bg_col ::print_color(bg_col)
seecolor
# Colour for highlighted text
<- "grey30"
text_hil ::print_color(text_hil)
seecolor
# Colour for the text
<- "grey20"
text_col ::print_color(text_col)
seecolor
theme_set(
theme_minimal(
base_size = bts,
base_family = "body_font"
+
) theme(
text = element_text(
colour = "grey30",
lineheight = 0.3,
margin = margin(0,0,0,0, "pt")
),plot.title = element_text(
hjust = 0.5
),plot.subtitle = element_text(
hjust = 0.5
)
)
)
# Caption stuff for the plot
::font_add(
sysfontsfamily = "Font Awesome 6 Brands",
regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf")
)<- ""
github <- "aditya-dahiya"
github_username <- ""
xtwitter <- "@adityadahiyaias"
xtwitter_username <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")
social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")
social_caption_2 <- paste0(
plot_caption "**Data**: Open Street Maps through {osmextract}",
" | **Code:** ",
social_caption_1, " | **Graphics:** ",
social_caption_2
)rm(github, github_username, xtwitter,
xtwitter_username, social_caption_1, social_caption_2)