Created
January 13, 2018 22:39
-
-
Save diegovalle/53e63da2f9a142dbf7f5d9fbe99f2278 to your computer and use it in GitHub Desktop.
This file contains 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(directlabels) | |
library(ggplot2) | |
library(scales) | |
library(tidyr) | |
df = data.frame(Canada = c(522, 609, 611), | |
US = c(15872, 17793, 19362), | |
Mexico = c(20010, 20762, 24559)) | |
df = data.frame(apply(df, 2, function(x) x = x/x[1])) | |
df$year = 2014:2016 | |
df = tidyr::gather(df, country, percent, -year) | |
p = ggplot(df, aes(year, percent, group = country, color = country)) + | |
geom_line() + | |
xlab("year") + | |
ylab("homicide count as a percentage of 2014") + | |
scale_x_continuous(breaks = (2014:2016), limits = c(2014,2016.3)) + | |
ggtitle("Homicides in Mexico, the US, and Canada 2014-2016 (2014 = 100%)" , | |
subtitle = "Sources: Statistics Canada, CANSIM, table 253-0001 and Homicide Survey, Canadian Centre for Justice Statistics, INEGI, and CDC Wonder") + | |
theme_bw() + | |
scale_y_continuous(labels=percent) | |
directlabels::direct.label(p, "last.bumpup") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment