<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/new-in-the-tigris-package-simple-features-support-and-historic-shapefiles/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://walkerke.github.io/2017/05/tigris-v05/"> Kyle Walker</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p></p>
<p>I am excited to announce that <strong>tigris</strong> 0.5 is now on CRAN. This is a major release that has been in the works for several months. Get it with <code>install.packages(&quot;tigris&quot;)</code>.</p>
<p>One major new feature is support for the simple features data model via the <a target="_blank" rel="nofollow" href="https://github.com/edzer/sfr">sf R package</a>. <strong>sf</strong> allows for the representation of spatial objects in R like data frames, but with a list-column containing feature geometry. This has multiple advantages, as objects of class <code>sf</code> accept <strong>tidyverse</strong> functions for data wrangling and are much faster to work with. For <strong>tigris</strong>, this means that large objects like Census blocks or national railroads are much more usable in R.</p>
<p>To return an object of class <code>sf</code> via <strong>tigris</strong>, either supply the argument <code>class = &quot;sf&quot;</code> or set this globally in your R session with <code>options(tigris_class = &quot;sf&quot;)</code>. For example:</p>
<pre><code>library(tigris)

options(tigris_class = &quot;sf&quot;)

co &lt;- counties(cb = TRUE)

head(co)</code></pre>
<pre><code>## Simple feature collection with 6 features and 9 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -88.47323 ymin: 31.18113 xmax: -85.04931 ymax: 33.00682
## epsg (SRID):    4269
## proj4string:    +proj=longlat +datum=NAD83 +no_defs
##   STATEFP COUNTYFP COUNTYNS       AFFGEOID GEOID    NAME LSAD      ALAND
## 1      01      005 00161528 0500000US01005 01005 Barbour   06 2291820706
## 2      01      023 00161537 0500000US01023 01023 Choctaw   06 2365954971
## 3      01      035 00161543 0500000US01035 01035 Conecuh   06 2201896058
## 4      01      051 00161551 0500000US01051 01051  Elmore   06 1601876535
## 5      01      065 00161558 0500000US01065 01065    Hale   06 1667804583
## 6      01      109 00161581 0500000US01109 01109    Pike   06 1740741211
##     AWATER                       geometry
## 1 50864677 MULTIPOLYGON(((-85.748032 3...
## 2 19059247 MULTIPOLYGON(((-88.473227 3...
## 3  6643480 MULTIPOLYGON(((-87.427204 3...
## 4 99850740 MULTIPOLYGON(((-86.413335 3...
## 5 32525874 MULTIPOLYGON(((-87.870464 3...
## 6  2336975 MULTIPOLYGON(((-86.199408 3...</code></pre>
<p><code>geo_join</code> and <code>rbind_tigris</code> still work with objects of class <code>sf</code>; however, you can use the <code>*_join</code> functions from the tidyverse as well.</p>
<p>The second major new feature is support for historic shapefiles going back to 1990. Historical data are available for the <code>states()</code>, <code>counties()</code>, <code>tracts()</code>, and <code>block_groups()</code> functions, and I’ve re-factored much of <strong>tigris</strong>’s code to easily accommodate other geographies if requested by users.</p>
<pre><code>library(purrr)

options(tigris_class = &quot;sp&quot;)

par(mfrow = c(1, 3))

walk(c(1990, 2000, 2010), function(year) {
  plot(tracts(&quot;TX&quot;, &quot;Denton&quot;, cb = TRUE, year = year), 
       main = paste0(&quot;Census tracts in Denton County, &quot;, 
                     as.character(year)))
})</code></pre>
<p><img width="450" src="http://walkerke.github.io/2017/05/tigris-v05/#%23%23%23%23../content/post/tigris-v05_files/figure-html/unnamed-chunk-2-1.png"></p>
<p>My motivation for these updates is twofold. First, I’m working on a new package called <strong>tidycensus</strong> that will integrate <strong>tigris</strong> with the decennial Census and American Community Survey APIs. This package will allow R users to return integrated spatial and demographic datasets as <code>sf</code> objects in one function call, and will be designed to work seamlessly within the tidyverse. Second, I’m starting a book project this summer called <em>Analyzing the US Census with R</em>. The book will cover Census data acquisition and wrangling; spatial modeling with Census data; and working with Census microdata from the <a target="_blank" rel="nofollow" href="https://www.ipums.org/">Integrated Public Use Microdata Series</a>, all within R. Look for updates on both projects in this space!</p>
<p></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://walkerke.github.io/2017/05/tigris-v05/"> Kyle Walker</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/WWIQdR50a_I"></a></div>