<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/workout-wednesday-redux-2017-week-3/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/01/18/workout-wednesday-redux-2017-week-3/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I had started a “52 Vis” initiative back in 2016 to encourage folks to get practice making visualizations since that’s the only way to get better at virtually anything. Life got crazy, 52 Vis fell to the wayside and now there are more visible alternatives such as <a target="_blank" rel="nofollow" href="http://www.makeovermonday.co.uk/">Makeover Monday</a> and <a target="_blank" rel="nofollow" href="http://www.vizwiz.com/p/workout-wednesday.html">Workout Wednesday</a>. They’re geared towards the “T” crowd (I’m not giving a closed source and locked-in-data product any more marketing than two links) but that doesn’t mean R, Python or other open-tool/open-data communities can’t join in for the ride and learning experience.</p>
<p>This week’s <a target="_blank" rel="nofollow" href="http://www.vizwiz.com/2017/01/workout-wednesday-state-of-us-jobs.html">workout</a> is a challenge to reproduce or improve upon a <a target="_blank" rel="nofollow" href="http://thedailyviz.com/2016/12/14/four-decades-of-state-unemployment-rates-in-small-multiples-part-2/">chart by Matt Stiles</a>. You should go to both (give them the clicks and eyeballs they both deserve since they did great work). They both chose a line chart, but the whole point of these exercises is to try out new things to help you learn how to communicate better. I chose to use <code>geom_segment()</code> to make mini-column charts since that:</p>
<ul>
<li>eliminates the giant rose-coloured rectangles that end up everywhere</li>
<li>helps show the differences a bit better (IMO), and</li>
<li>also helps highlight some of the states that have had more difficulties than others</li>
</ul>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/rud.is/b/wp-content/uploads/2017/01/state_of_us_1.png?ssl=1"><img alt="" class="wp-image-4919" src="https://i1.wp.com/rud.is/b/wp-content/uploads/2017/01/state_of_us_1.png?resize=456%2C1120&ssl=1" data-recalc-dims="1"></a></p>
<p>Click/tap to “embiggen”. I kept the same dimensions that Andy did but unlike Matt’s creation this is a plain ol’ PNG as I didn’t want to deal with web fonts (I’m on a Museo Sans Condensed kick at the moment but don’t have it in my TypeKit config yet). I went with official annual unemployment numbers as they may be calculated/adjusted differently (I didn’t check, but I knew that data source existed, so I used it).</p>
<p>One reason I’m doing this is a quote on the Workout Wednesday post:</p>
<blockquote>
<p><em>This will be a very tedious exercise. To provide some context, <strong>this took me 2-3 hours to create</strong>. Don’t get discouraged and don’t feel like you have to do it all in one sitting. Basically, try to make yours look identical to mine.</em></p>
</blockquote>
<p>This took me <strong>10 minutes to create in R</strong>:</p>
<pre><code>#' ---
#' output:
#'  html_document:
#'    keep_md: true
#' ---
#+ message=FALSE
library(ggplot2)
library(hrbrmisc)
library(readxl)
library(tidyverse)

# Use official BLS annual unemployment data vs manually calculating the average
# Source: https://data.bls.gov/timeseries/LNU04000000?years_option=all_years&amp;periods_option=specific_periods&amp;periods=Annual+Data
read_excel(&quot;~/Data/annual.xlsx&quot;, skip=10) %>%
  mutate(Year=as.character(as.integer(Year)), Annual=Annual/100) -> annual_rate


# The data source Andy Kriebel curated for you/us: https://1drv.ms/x/s!AhZVJtXF2-tD1UVEK7gYn2vN5Hxn #ty Andy!
read_excel(&quot;~/Data/staadata.xlsx&quot;) %>%
  left_join(annual_rate) %>%
  filter(State != &quot;District of Columbia&quot;) %>%
  mutate(
    year = as.Date(sprintf(&quot;%s-01-01&quot;, Year)),
    pct = (Unemployed / `Civilian Labor Force Population`),
    us_diff = -(Annual-pct),
    col = ifelse(us_diff&lt;0,
               &quot;Better than U.S. National Average&quot;,
               &quot;Worse than U.S. National Average&quot;)
  ) -> df

credits &lt;- &quot;Notes: Excludes the District of Columbia. 2016 figure represents October rate.\nData: U.S. Bureau of Labor Statistics &lt;https://www.bls.gov/lau/staadata.txt>\nCredit: Matt Stiles/The Daily Viz &lt;thedailyviz.com>&quot;

#+ state_of_us, fig.height=21.5, fig.width=8.75, fig.retina=2
ggplot(df, aes(year, us_diff, group=State)) +
  geom_segment(aes(xend=year, yend=0, color=col), size=0.5) +
  scale_x_date(expand=c(0,0), date_labels=&quot;'%y&quot;) +
  scale_y_continuous(expand=c(0,0), label=scales::percent, limit=c(-0.09, 0.09)) +
  scale_color_manual(name=NULL, expand=c(0,0),
                     values=c(`Better than U.S. National Average`=&quot;#4575b4&quot;,
                              `Worse than U.S. National Average`=&quot;#d73027&quot;)) +
  facet_wrap(~State, ncol=5, scales=&quot;free_x&quot;) +
  labs(x=NULL, y=NULL, title=&quot;The State of U.S. Jobs: 1976-2016&quot;,
       subtitle=&quot;Percentage points below or above the national unemployment rate, by state. Negative values represent unemployment rates\nthat were lower — or better, from a jobs perspective — than the national rate.&quot;,
       caption=credits) +
  theme_hrbrmstr_msc(grid=&quot;Y&quot;, strip_text_size=9) +
  theme(panel.background=element_rect(color=&quot;#00000000&quot;, fill=&quot;#f0f0f055&quot;)) +
  theme(panel.spacing=unit(0.5, &quot;lines&quot;)) +
  theme(plot.subtitle=element_text(family=&quot;MuseoSansCond-300&quot;)) +
  theme(legend.position=&quot;top&quot;)</code></pre>
<p>Swap out <code>~/Data</code> for where you stored the files.</p>
<p>The “weird” looking comments enable me to <a target="_blank" rel="nofollow" href="https://yihui.name/knitr/demo/stitch/">spin</a> the script and is pretty much just the inverse markup for <code>knitr</code> R Markdown documents. As the comments say, you should really thank Andy for curating the BLS data for you/us. </p>
<p>If I really didn’t pine over aesthetics it would have taken me 5 minutes (most of that was waiting for re-rendering). Formatting the blog post took much longer. Plus, I can update the data source and re-run this in the future without clicking anything. This re-emphasizes a caution I tell my students: <em>beware of dragon droppings</em> (“drag-and-drop data science/visualization tools”).</p>
<p>Hopefully you presently follow or will start following Workout Wednesday and Makeover Monday and dedicate some time to hone your skills with those visualization <em>katas</em>. </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="https://rud.is/b/2017/01/18/workout-wednesday-redux-2017-week-3/"> R – rud.is</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/zsJ-quXwosE"></a></div>