Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

r - Creating a stacked bar chart centered on zero using ggplot

I'm currently working with a stacked horizontal bar graph chart using ggplot2 in R.

This is my R code:

ggplot(results, aes(x=Protocol, y=Time, fill=Phase)) + 
  geom_bar(stat="identity") + coord_flip()

And it produces this graph: Example Graph

I want to center this chart so that Phase 1 and 2 are on the left and Phase 3 and 4 are on the right.

Here is a rough idea of what I'm looking for. But imagine the center line is time 0, and time goes positive in either direction: Example of Goal

I'm thinking I should make two graphs back to back?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This type of chart is used a lot for likert-type survey data which shows positive and negative perception around a central point

What you're trying to do I called the 'Net Stacked Distribution' in a post early 2011 and is also called a diverging bar chart. You'll find it referred to in both ways. Willard Brinton used it in his 1939 book 'Graphic Presentation'. There is quite a lot out there.

My example and explanation, with code for Tableau: http://www.organizationview.com/net-stacked-distribution-a-better-way-to-visualize-likert-data

Naomi Robbins wrote a paper on it: http://www.amstat.org/membersonly/proceedings/2011/papers/300784_64164.pdf

A few R examples:

There's a Likert package by Jason Bryer with a corresponding site: http://jason.bryer.org/likert/

The HH package implements it in lattice

A really good explanation on Cross Validated: https://stats.stackexchange.com/questions/25109/visualizing-likert-responses-using-r-or-spss

Jason Becker: http://blog.jsonbecker.com/2012/07/ranked-likert-scale-visualization.html

Ethan Brown: http://statisfactions.com/2012/improved-net-stacked-distribution-graphs-via-ggplot2-trickery/

Daniel Luedecke: http://strengejacke.wordpress.com/2013/07/17/plotting-likert-scales-net-stacked-distributions-with-ggplot-rstats/

The biggest bit of controversy on these charts is what to do with a neutral value. Naomi recommends splitting it either side of the central axis. I argued that a neutral value is neither positive nor negative and therefore we should treat it effectively as a zero and not show it on the chart (it can be plotted, along with the Not Applicable values on a secondary graph or chart).

I've done some usability testing on these charts and whilst they perform better than many other values something simpler like a net figure (positive sentiments - negative sentiments, similar to how the Net Promoter Score is calculated) seems to be preferred.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...