Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Created August 1, 2023 13:13
Show Gist options
  • Save matt-dray/f3d484d5cd14c25185b56dc25c23cca4 to your computer and use it in GitHub Desktop.
Save matt-dray/f3d484d5cd14c25185b56dc25c23cca4 to your computer and use it in GitHub Desktop.
A stunning dual-y-axis chart to commemorate the reduction of people in the office called Bertha (not actual name) and the ensuing sadness.
library(ggplot2)
library(ggthemes)
library(extrafont)
font_import() # might take a minute
loadfonts(device = "win")
df <- data.frame(
Time = 1:3,
Berthas = 2:0,
Sadness = 0:2
)
ggplot(df) +
geom_bar(aes(Time, Berthas), stat = "identity") +
scale_y_continuous(sec.axis = sec_axis(~., name = "Sadness")) +
geom_point(aes(Time, Sadness), size = 3) +
geom_path(aes(Time, Sadness), linewidth = 1) +
labs(
title = "Very important graph",
subtitle = "Such y axes, very datums",
caption = "Copyright forever and ever: Matt Dray"
) +
theme_excel() +
theme(
text = element_text(
size = 16,
family = "Comic Sans MS"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment