Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aboriginal (Canada) and American Indian or Alaska Native (U.S.A.) homicide rates
library("ggplot2")
library("gridExtra")
addSource <- function(plot, text = "") {
plot <- arrangeGrob(plot,
sub = textGrob(text,
x = 0, hjust = -0.1, vjust=0.1,
gp = gpar(fontface = "italic", fontsize = 9,
col = "gray30")))
return(plot)
}
rates = data.frame(country = c("Canada", "U.S.A"), rate = c(8.8, 7.8))
rates$country = with(rates, reorder(country, rate))
p <- ggplot(rates, aes(country, rate, fill = country)) +
geom_bar(stat = "identity") +
coord_flip() +
ggtitle("Aboriginal (Canada) and American Indian or Alaska Native (U.S.A.) homicide rates") +
xlab("homicide rate") +
scale_fill_manual(values = c("#000099", "#FF0000"), breaks = c("Canada", "U.S.A"))
addSource(p, "Canadian data 1997-2000; USA data 1999-2000. Source: Statistics Canada (http://bit.ly/1GU1EcO) and CDC Wonder")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.