Last active
August 29, 2015 14:15
-
-
Save mrecos/8a6b4831e65c9431338b to your computer and use it in GitHub Desktop.
Qucik setup to produce statebins choropleth-like map
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
### Qucik setup to produce statebins choropleth-like map | |
devtools::install_github("hrbrmstr/statebins") | |
# Data from American Fact Finder http://factfinder.census.gov/faces/nav/jsf/pages/index.xhtml | |
s <- c('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming') | |
x <- c('12811', '183', '364', '11873', '10064', '1469', '344', '0', '5015', '13822', '104', '6571', '1217', '4061', '987', '112', '6130', '4396', '4261', '1083', '1598', '4857', '1852', '9770', '3377', '3335', '292', '0', '1442', '231', '22', '3652', '11335', '20', '3055', '789', '17428', '9188', '0', '6298', '942', '6248', '6580', '94', '1341', '8204', '15054', '3977', '9088', '324') | |
xp <- c('5.95140760011149', '0.085013472080275', '0.169097835176066', '5.51565548638855', '4.67527640992288', '0.68243054910341', '0.159806745331227', '0', '2.32974077859333', '6.42107219176809', '0.0483136671931618', '3.05258756852179', '0.565362817058441', '1.88655579299452', '0.458515283842795', '0.0520301031310973', '2.84771903744309', '2.04218154789557', '1.97946669144291', '0.503112515098021', '0.74235807860262', '2.2563411688191', '0.860354919632073', '4.53869738920375', '1.56880052030103', '1.54928923162687', '0.135649911734646', '0', '0.669887577812877', '0.107312087707888', '0.0102201988293227', '1.69655300566757', '5.26572516956239', '0.0092910898448388', '1.41921397379913', '0.366533494378891', '8.09625569079253', '4.26832667471894', '0', '2.92576419213974', '0.437610331691907', '2.90253646752764', '3.05676855895197', '0.0436681222707424', '0.622967574096442', '3.81120505435288', '6.99340332621016', '1.8475332156462', '4.22187122549475', '0.150515655486389') | |
x <- as.numeric(x) | |
xp <- as.numeric(xp) | |
dat <- data.frame(state = s, x = x, xp = xp) | |
dat$state <- as.character(dat$state) | |
b <- hist(dat$xp, plot=FALSE, breaks=5) # read breaks, formatted manually into labels= below | |
g <- statebins(dat, state_col = "state", value_col = "xp", breaks=5, labels=c("0-2", "2-4", "4-6", "6-8", "8-9"), | |
font_size=6, brewer_pal="PiYG", text_color="black", plot_title = "Distribution of Sawmill Labor", title_position = "top", | |
state_border_col = "black", legend_title = "Percent of labor force", legend_position="bottom") | |
plot(g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment