Reputation: 534
I have a list of lat and long for several thousand members and want to append their census tract block group code(i.e. 36001038141345). My first thought is to plot these members on a map that has a us census block group layer. Then either use an overlay function from one of the mapping packages for example, or instead of using shape files convert file to data frame and use a join function for example from "ggplot" and "ggmap" to match the lat and long to the 14 digit census block group value.
## Example of results: ##
GEOID10 LAT LONG
1. 1005950300123 +31.7908933 -085.5670514
2. 01005950900134 +31.8467221 -085.1462332
3. 01005950800145 +31.9206930 -085.1760317
4. 01005950700156 +31.9440855 -085.2620842
5. 01005950600167 +31.8783526 -085.2729215
6. 01005950100178 +32.0353533 -085.2477678
7. 01005950400189 +31.6794432 -085.5577196
8. 01005950200200 +31.9222753 -085.4498309
9. 01005950500211 +31.7634183 -085.2718649
10. 01027959000222 +33.3093759 -085.8820883
11. 01027959200233 +33.1781831 -086.0215486
12. 01027958900244 +33.3872783 -085.7690615
I am searching for a us census block group shape file to use in R. A shape file that might work is a separate download for all US states using Tiger files at US census site along with the necessary support files (".shp, .dbf, .prj etc.") making using this file problematic because it would result in a couple of hundred needed files.
Also checked the UScensus2010 package but it doesn't yet have the 'install.blkgrp' function set up. I'm reaching out to get some ideas or direction on what is the best way to do this.
Thank you
Upvotes: 3
Views: 1344
Reputation: 99
I found this was the easiest way to download census tract shape files using R:
if (("tigris" %in% rownames(installed.packages()))==FALSE)install.packages("tigris"); library(tigris)
if (("ggplot2" %in% rownames(installed.packages()))==FALSE)install.packages("ggplot2"); library(ggplot2)
census.tracts <- tracts(state="NJ")
plot(census.tracts)
census.tracts.fort <- fortify(census.tracts)
This piece of code will give you a census tract shape file for the state of New Jersey. Late to the party I know, but I hope this process can help others.
Upvotes: 1