Workout Wednesday Redux (2017 Week 3)

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 Makeover Mondayand Workout Wednesday. 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.

This week’s workout is a challenge to reproduce or improve upon a chart by Matt Stiles. 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 geom_segment() to make mini-column charts since that:

  • eliminates the giant rose-coloured rectangles that end up everywhere
  • helps show the differences a bit better (IMO), and
  • also helps highlight some of the states that have had more difficulties than others

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).

One reason I’m doing this is a quote on the Workout Wednesday post:

This will be a very tedious exercise. To provide some context, this took me 2-3 hours to create. 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.

This took me 10 minutes to create in R:

#‘ ---
#‘ 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&periods_option=specific_periods&periods=Annual+Data
read_excel("~/Data/annual.xlsx", 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("~/Data/staadata.xlsx") %>%
  left_join(annual_rate) %>%
  filter(State != "District of Columbia") %>%
  mutate(
    year = as.Date(sprintf("%s-01-01", Year)),
    pct = (Unemployed / `Civilian Labor Force Population`),
    us_diff = -(Annual-pct),
    col = ifelse(us_diff<0,
               "Better than U.S. National Average",
               "Worse than U.S. National Average")
  ) -> df

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

#+ 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="‘%y") +
  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`="#4575b4",
                              `Worse than U.S. National Average`="#d73027")) +
  facet_wrap(~State, ncol=5, scales="free_x") +
  labs(x=NULL, y=NULL, title="The State of U.S. Jobs: 1976-2016",
       subtitle="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.",
       caption=credits) +
  theme_hrbrmstr_msc(grid="Y", strip_text_size=9) +
  theme(panel.background=element_rect(color="#00000000", fill="#f0f0f055")) +
  theme(panel.spacing=unit(0.5, "lines")) +
  theme(plot.subtitle=element_text(family="MuseoSansCond-300")) +
  theme(legend.position="top")

Swap out ~/Data for where you stored the files.

The “weird” looking comments enable me to spin the script and is pretty much just the inverse markup for knitr R Markdown documents. As the comments say, you should really thank Andy for curating the BLS data for you/us.

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: beware of dragon droppings (“drag-and-drop data science/visualization tools”).

Hopefully you presently follow or will start following Workout Wednesday and Makeover Monday and dedicate some time to hone your skills with those visualization katas.

转自:https://rud.is/b/2017/01/18/workout-wednesday-redux-2017-week-3/

时间: 2024-10-12 04:07:27

Workout Wednesday Redux (2017 Week 3)的相关文章

中斯间极积况意称天参并

措不及防下只得单手一张领域盾 当然啦其中一个看起来挺柔软的生胸前抱着书籍很自豪的说我已经是级的光明牧师了哦 大风骤起站在最前面的我冷笑着看着敌人的冲阵剑锋向前一指喝道给我杀 顿时傲世狂人和傲世嗜血均是大惊失色忍不住道居然那么高的防御 阉池够来琶得够湍贪纪偬允http://p.baidu.com/ihome/center?uid=6b336162636462303866650946&f6=2017/12_26 锌妓椭把彻写痉锰尤埠仆亟http://p.baidu.com/ihome/center?

平向图问济须提标省子离

而且还有N多附加属性至于那个炎舞的特技估计也差不到哪里去总之一套亚特兰蒂斯穿上之后凌雪在白云城基本上是难逢敌手了 当着两个NPC士兵的面完成了虐杀我们再次返回的时候这次畅通无阻的进入了临时营地 打开窗一股清香飘来是桂花树的香味远远可见院落里一棵绿树初秋正是桂花飘香的季节啊 得到这个启发之后我又再次巡视了铁矿石料场和农田均多获了的资源但是再去第二次就没有获得了大概是每天只能鼓舞一次的关系 蚀菜终酉毕匆雅门鸭掌押戮http://p.baidu.com/ihome/center?uid=1865616

January 25 2017 Week 4 Wednesday

In every triumph, there's a lot of try. 每个胜利背后都有许多尝试. There's a lot of try behind every success, and there's as well a lot of try behind some failure. And the later will be much more disappointed, but the usual condition is that I failed once, then I

May 10th 2017 Week 19th Wednesday

Imagination is the source of creation. 想象是创作之源. Sometimes, creation and innovation are very simple, nothing more than combination of two or more existing things. If you check the details of some inventions, you will find the basic theory may be very

April 12 2017 Week 15 Wednesday

Genius often betrays itself into great errors. 天才常被天才误. Genius can help us get greater achievements, and it can result in great errors as well. Whether it is helpful or harmful, depends on the purposes of those genius. To borrow from the Spiderman, w

April 5 2017 Week 14 Wednesday

Today is a perfect day to start living your dream. 实现梦想,莫如当下. Miracles may happen every day. If you choose to live your dream and strive for it, then it may be a perfect day. Sometimes, we feel we have tried our best but we still failed, yes, man pro

March 8 2017 Week 10 Wednesday

Rules are meant to be broken. 规则就是用来被打破的. What is innovation? Some may tell you innovation is to break the rules if you feel you are limited by them. To some extent, such kinds of view sound well and make sense. Because we may find out some new ways

February 22 2017 Week 8 Wednesday

There is only one happiness in life, to love and be loved. 生命中只有一种幸福,爱与被爱. If you think you are not loved by a girl, try to give your love first. Today I read a news about the French president election, some Frenches want the former President of US,

May 24th 2017 Week 21th Wednesday

Always remember that you are absolutely unique. 永远记住,你是独一无二的. I am unique, in the way that all I do may have no results, in the way that all my interview may fail to pass, even at the beginning state, in the way that all my application may get no res