Created
August 3, 2014 20:32
-
-
Save earino/ab49e04282f047eedfde to your computer and use it in GitHub Desktop.
joke_map.R
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
joke_map <- function(states_to_highlight, title="", highlight_colors=c("#aaaaaa", "#ee0000")) { | |
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
library(maps) | |
highlighting = data.frame(region=tolower(state.name[match(states_to_highlight, state.abb)]), | |
highlight=TRUE) | |
d = map_data("state") %>% left_join(highlighting, by="region") | |
d[is.na(d$highlight),]$highlight <- FALSE | |
p <- ggplot(d) + geom_polygon(aes(x=long, y=lat, | |
group = group, fill=highlight), | |
colour="black") + | |
scale_fill_manual(values=highlight_colors) + | |
ggtitle(title) + | |
xlab("") + | |
ylab("") + | |
theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) + | |
guides(fill=FALSE) | |
p | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment