Skip to content

Instantly share code, notes, and snippets.

@edavidaja
Created February 25, 2020 23:38
Show Gist options
  • Save edavidaja/e00160c861c94f5e8b4d60184b6121e1 to your computer and use it in GitHub Desktop.
Save edavidaja/e00160c861c94f5e8b4d60184b6121e1 to your computer and use it in GitHub Desktop.
categorical legends with ggtext
library(ggplot2)
library(ggtext)
 
dat <- economics_long[economics_long$variable %in% c("psavert", "uempmed"), ]
ggplot(dat, aes(date, value, color = variable)) +
  geom_line() +
  scale_color_manual(values = c("#0072B2", "#009E73")) +
  labs(
    x = "", y = "",
    title = "<span style='color:#0072B2'>savings</span> and <span style='color:#009E73'>unemployment duration</span>" 
  ) +
  theme(
    plot.title = element_markdown()
  ) +
  guides(color = "none")

Created on 2020-02-25 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment