I woke up this morning to a [headline story from the Washington Post](https://www.washingtonpost.com/news/the-fix/wp/2015/12/10/to-many-christian-terrorists-arent-true-christians-but-muslim-terrorists-are-true-muslims/) on _”Americans are twice as willing to distance Christian extremists from their religion as Muslims_”. This post is not about the content of the headline or story. It _is_ about the horrible pie chart WaPo led the article with:
This isn’t just a rant of a madman against pie charts. While I _am_ vehemently opposed to them, we did cover them [in our book](https://books.google.com/books?id=7DqwAgAAQBAJ&pg=PA146&lpg=PA146&dq=data-driven+security+pie+chart&source=bl&ots=Cy1iJylsHd&sig=a6Hz1JB-QYLq6H0VZJpPleJgRkQ&hl=en&sa=X&ved=0ahUKEwj79uqt_tjJAhVG0iYKHS0uDn4Q6AEIMzAH#v=onepage&q=data-driven%20security%20pie%20chart&f=false) and my co-author (@jayjacobs) and the incredibly talented @annkemery both agree there are often cases where they are appropriate. Even using their less-sensitive sensibilities, this would not be one of those cases.
So, what—exactly—is the problem? WaPo tried to enable comparison between pies by exploding them and using colors to indicate similar fear levels, mapping shades to entries in the top legend. Your eye has to move around a bit to take everything in and remember the mapping as you focus on each slice (since you will end up doing that given that each category colored differently). Their whole goal was to enable the reader to see the change in sentiment towards terrorism since this time last year.
Hrm. Two dates. Small set of values. Desire to quickly compare change in value/slope. **This sounds like a job for a slopegraph!**
The article and graphic are based on a [survey](http://publicreligion.org/research/2015/12/survey-nearly-half-of-americans-worried-that-they-or-their-family-will-be-a-victim-of-terrorism/). Thankfully the [complete survey data was made available](http://publicreligion.org/site/wp-content/uploads/2015/12/December-2015-PRRI-RNS-Topline1.pdf), which made it easy to do a makeover (in R of course). Here’s the result:
Each category change is clearly visible, you don’t need to remember color association and you even know the actual values*.
The R code is below and in [this gist](https://gist.github.com/hrbrmstr/9bf4f93dffc1df48fe27). How would you make the WaPo chart better (drop a note in the comments with a link to your own makeover)?
library(tidyr) library(ggplot2) library(ggthemes) library(scales) library(dplyr) # Easiest way to transcribe the PDF table # The slope calculation will enable us to color the lines/points based on up/down dat <- data_frame(`2014-11-01`=c(0.11, 0.22, 0.35, 0.31, 0.01), `2015-12-01`=c(0.17, 0.30, 0.30, 0.23, 0.00), slope=factor(sign(`2014-11-01` - `2015-12-01`)), fear_level=c("Very worried", "Somewhat worried", "Not too worried", "Not at all", "Don't know/refused")) # Transform that into something we can use dat <- gather(dat, month, value, -fear_level, -slope) # We need real dates for the X-axis manipulation dat <- mutate(dat, month=as.Date(as.character(month))) # Since 2 categories have the same ending value, we need to # take care of that (this is one of a few "gotchas" in slopegraph preparation) end_lab <- dat %>% filter(month==as.Date("2015-12-01")) %>% group_by(value) %>% summarise(lab=sprintf("%s", paste(fear_level, collapse=", "))) gg <- ggplot(dat) # line gg <- gg + geom_line(aes(x=month, y=value, color=slope, group=fear_level), size=1) # points gg <- gg + geom_point(aes(x=month, y=value, fill=slope, group=fear_level), color="white", shape=21, size=2.5) # left labels gg <- gg + geom_text(data=filter(dat, month==as.Date("2014-11-01")), aes(x=month, y=value, label=sprintf("%s — %s ", fear_level, percent(value))), hjust=1, size=3) # right labels gg <- gg + geom_text(data=end_lab, aes(x=as.Date("2015-12-01"), y=value, label=sprintf(" %s — %s", percent(value), lab)), hjust=0, size=3) # Here we do some slightly tricky x-axis formatting to ensure we have enough # space for the in-panel labels, only show the months we need and have # the month labels display properly gg <- gg + scale_x_date(expand=c(0.125, 0), labels=date_format("%b\n%Y"), breaks=c(as.Date("2014-11-01"), as.Date("2015-12-01")), limits=c(as.Date("2014-02-01"), as.Date("2016-12-01"))) gg <- gg + scale_y_continuous() # I used colors from the article gg <- gg + scale_color_manual(values=c("#f0b35f", "#177fb9")) gg <- gg + scale_fill_manual(values=c("#f0b35f", "#177fb9")) gg <- gg + labs(x=NULL, y=NULL, title="Fear of terror attacks (change since last year)\n") gg <- gg + theme_tufte(base_family="Helvetica") gg <- gg + theme(axis.ticks=element_blank()) gg <- gg + theme(axis.text.y=element_blank()) gg <- gg + theme(legend.position="none") gg <- gg + theme(plot.title=element_text(hjust=0.5)) gg