<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/us-immigration-enforcement-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.stoltzmaniac.com/us-immigration-enforcement-part-1/"> R-Projects – Stoltzmaniac</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>Trend of US Immigration Enforcement</h3>
<p>In the coming months I’ll be digging into the immigration enforcement data posted on <a rel="nofollow" href="https://data.world/stoltzmaniac/insights-from-the-usa" target="_blank">data.world</a>. I encourage anyone to take this data and either add to the project or to do something on their own. I will be bringing in external data sources to merge as well (which I did for this first plot).</p>
<p>If you’re only here for a “high-level nugget” of information, the basic thing you can see is:</p>
<h4>Things have changed since 1925!</h4>
<p><span></span></p>
<p>Using R packages ggplot2 and ggtheme, I produced a plot of the immigration enforcement data with the party of the POTUS shown in red and blue:</p>
<hr>
<p><img alt="plot of chunk immigration enforcement plots" title="plot of chunk immigration enforcement plots" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/08/immigration-enforcement-plots-1.png?w=620&ssl=1" data-recalc-dims="1"></p>
<hr>
<h4>What’s going on here?</h4>
<p>I am not a huge history buff, so when I noticed the big spike back in the early 1950’s I went to look it up. It’s certainly something worth reading about. It stemmed from the <a rel="nofollow" href="https://en.wikipedia.org/wiki/Bracero_program" target="_blank">Bracero Program</a> followed by <a rel="nofollow" href="https://en.wikipedia.org/wiki/Operation_Wetback%22" target="_blank">Operation Wetback</a>:</p>
<blockquote><p>Operation Wetback was the culmination of more than a decade of intensifying immigration enforcement. Immigration enforcement actions (removals and returns) rose rapidly from a low of 12 thousand in 1942, to 727 thousand in 1952, the final year of the Truman Administration. Enforcement actions continued to rise under Eisenhower, until reaching a peak of 1.1 million in 1954, the year of Operation Wetback. Enforcement actions then fell by more than 90 percent in 1955, and 1956, and in 1957 were 69 thousand, the lowest number since 1944. The number of enforcement actions rose again in the 1960s and 1970s, but did not exceed the 1954 peak of Operation Wetback until 1986.</p>
</blockquote>
<p>I apologize for what may be considered offensive or derogatory language but that’s what the operation was called.</p>
<h4>Why is the political party of the POTUS on there?</h4>
<p>The short answer – because it makes for a more interesting graph. In addition, immigration is a hot topic and presidents around the world have been discussing it for quite some time now (understatement). I certainly realize that the role of the POTUS has changed over the years. Obviously, there are <strong><em>A LOT</em></strong> of people who are involved in immigration enforcement policy, decision-making and execution. Simply using the party of the POTUS isn’t reflective of the overall picture. Over the last decade, the power for the POTUS to affect immigration decisions has grown drastically. It will be interesting to see what this chart looks like five years from now.</p>
<p>The code can be found on my <a rel="nofollow" href="https://github.com/stoltzmaniac/Insights-From-the-USA" target="_blank">GitHub Repo</a></p>
<p>The project and data can be found on my <a rel="nofollow" href="https://data.world/stoltzmaniac/insights-from-the-usa" target="_blank">Data.World Project</a></p>
<pre><code>library(data.world)
library(tidyverse)
library(gridExtra)
library(scales)
library(GGally)
library(lubridate)
library(ggthemes)

# Datasets are referenced by their URL or path
dataset_key &lt;- &quot;https://data.world/stoltzmaniac/insights-from-the-usa&quot;

qry = data.world::qry_sql(sprintf(&quot;SELECT * FROM `%s`&quot;, &quot;immigrationenforcement&quot;))
data = data.world::query(qry, dataset = dataset_key)

qry = data.world::qry_sql(sprintf(&quot;SELECT * FROM `%s`&quot;, &quot;presidents&quot;))
presidents = data.world::query(qry, dataset = dataset_key)
presidents$left_office = as.Date(presidents$left_office,&quot;%d/%m/%Y&quot;)

# Removing William Henry Harrison due to only serving 31 days in office... not his fault!
df.presidents = presidents %>%
  filter(president != 'William Henry Harrison') %>%
  mutate(year_took_office = as.integer(year(took_office)),
         year_left_office = as.integer(year(left_office))) %>%
  select(president,year_took_office, year_left_office, party)

#modify Calvin Coolidge so the data lines up at the beginning
df.presidents$year_took_office[df.presidents$president == 'Calvin Coolidge'] = 1925

df = data %>%
  left_join(df.presidents, by = c('year' = 'year_took_office')) %>% 
  arrange(year) %>% 
  fill(everything())
df$year = as.integer(df$year)
df$party = factor(df$party)
df %>% arrange(year)

p1 = ggplot(df, aes(x=year,y=apprehended)) +
  geom_bar(stat='identity',aes(fill=party)) + 
  geom_line(size=1) + 
  scale_y_continuous(labels = comma) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_x_continuous(breaks = pretty(data$year, n = 10)) + 
  scale_fill_manual(values = c('#0052A5','#E0162B')) + 
  ggtitle('Apprehended') + 
  theme_fivethirtyeight()

p2 = ggplot(df, aes(x=year,y=removals)) + 
  geom_bar(stat='identity',aes(fill=party)) + 
  geom_line(size=1) + 
  scale_y_continuous(labels = comma) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_x_continuous(breaks = pretty(data$year, n = 10)) + 
  scale_fill_manual(values = c('#0052A5','#E0162B')) + 
  ggtitle('Removals') + 
  theme_fivethirtyeight()

p3 = ggplot(df, aes(x=year,y=returns)) + 
  geom_bar(stat='identity',aes(fill=party)) + 
  geom_line(size=1) + 
  scale_y_continuous(labels = comma) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_x_continuous(breaks = pretty(data$year, n = 10)) + 
  scale_fill_manual(values = c('#0052A5','#E0162B')) + 
  ggtitle('Returns') + 
  theme_fivethirtyeight()

grid.arrange(p1, p2, p3, ncol = 1)
</code></pre>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.stoltzmaniac.com/us-immigration-enforcement-part-1/"> R-Projects – Stoltzmaniac</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/aKpBOGZqspU" height="1"></a></div>