Skip to content

Instantly share code, notes, and snippets.

@ccamara
Created February 28, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/dc6455f6c7a6846e3b70fba72bd75ce4 to your computer and use it in GitHub Desktop.
Save ccamara/dc6455f6c7a6846e3b70fba72bd75ce4 to your computer and use it in GitHub Desktop.
Annotation in #R #ggplot
# Source: http://sharpsightlabs.com/blog/simple-annotate-plot-ggplot2/
ggplot(df, aes(x = Año, y = Población, group = 1)) +
geom_line(colour = "red", size = 1.5) +
geom_point(colour = "red", size = 4, shape = 21, fill = "white") +
geom_text(aes(label = Año), size = 3, hjust = 0.5, vjust = 3, position = "stack") +
scale_y_continuous(labels = function(x) format(x, big.mark = ".", scientific = FALSE)) +
ggtitle("Evolución de población en Detroit") +
labs(x = "Año", y = "Población") +
geom_vline(xintercept = 1973, linetype = "dashed") +
annotate("text", label = "Crisis petróleo", x = 1975, y = 75000, color = "black")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment