Created
April 9, 2018 23:17
-
-
Save jkaupp/7600bc43873fa8887d3bb75104bddfd6 to your computer and use it in GitHub Desktop.
One method for adding nicely aligned labels to line graphs in ggplot2
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(nycflights13) | |
plot_data <- flights %>% | |
filter(carrier %in% c("AA","UA")) %>% | |
count(year, month, carrier) | |
ggplot(plot_data, aes(x = month, y = n, group = carrier)) + | |
geom_path() + | |
geom_text(data = filter(plot_data, month == 12), aes(label = carrier), nudge_x = 0.5) + | |
scale_x_continuous(limits = c(1,13), breaks = 1:12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment