# How to add a third variable to a bar plot?

I'm trying to find the best way to show the following data:

Course                               Grade  Avg   Diff.    Semester
EECE 253 - Circut Analysis II        64     71    -7       Two
MATH 253 - Multivariable Calculus    63     68    -5       One
EECE 360 - Systems and Control       73     73     0       Three
EECE 269 - Signals and Systems       63     62     1       Two
EECE 352 - Materials and Devices     69     68     1       Three
EECE 356 - Electrical Circuits II    70     69     1       Three
POLI 369 - International Security    79     78     1       Three
EECE 353 - Digital Systems Design    81     79     2       Three
CPSC 259 - Data Structs & Algrithms  78     74     4       Two
EECE 251 - Circuit Analysis I        87     82     5       One
EECE 259 - Intro to Microcomputers   76     70     6       One
EECE 281 - Project Design Studio     92     85     7       Two
EECE 261 - Electromagnetics          67     59     8       Two
MATH 264 - Vector Calculus           67     58     9       Two
MATH 256 - Differential Equations    82     71    11       One
APSC 201 - Technical Communication   96     83    13       One


So far this is what I have: (feel free to play with it here)

I like the idea of displaying it sorted by difference so you can see what subjects I lagged in and did well in, so I've tried like this:

But I also want to figure out how to incorporate the semester into the graph to see what semesters I did better/worse in, like so:

How could I incorporate the semester into the bar graph as well as sort it by difference? Or alternatively, should I throw out the bar graph idea and use an altogether different graph?

• Bonus question: I've tried using tools like this and this to help me figure out the best graphs for certain situations, but they aren't always complete enough and don't have some less common but gorgeous graph types I've seen posted here. Can you recommend any other tools like this? Apr 30, 2015 at 23:07

I'd avoid bar charts here. A dot chart like this scores more highly on most criteria for such data. The term "dot chart" (or "dot plot") is overloaded in statistical graphics. This flavour is often called a Cleveland dot chart after William S. Cleveland, who promoted its use from the mid-1980s on. See a link to Cleveland's website here

Key points:

1. Bars can just take up a lot of space and a lot of ink. Here the grades and the averages are all more than 50%. We can give up the less important idea that the scale should start at 0 in favour of the more important idea that we should do justice to the interesting variation.

2. We can use sorting to help see some patterns. You said semester was important, so that we can respect that. Within each semester we sort first on the grades. We could sort on the averages or the differences.

3. Using open or hollow circles o and plus signs + as two symbols means that we can see where values differ (easy) and also where they are close (more difficult). o and + don't occlude each other even when values are identical.

As a bonus, some typos in course names were corrected. It seems that you care about the Departments, course numbers and course names. In other problems, such text descriptors would often be shortened. Here there is enough space, especially when you start the scale at 50. You had to choose a small font in your design, but that can be avoided.

Here is a variation in which the grades are sorted by the difference (grade $-$ average):

Something often has to be downplayed. In this design I give up on the idea of showing differences explicitly: they are just implicit.

For the record, this was done with the Stata code below. Something similar should be trivial in all major statistical programs.

graph dot (asis) Avg (asis) Grade, over(Course, sort(2) descending) exclude0 yla(50(10)100) scheme(s1color) marker(1, ms(Oh)) marker(2, ms(plus)) linetype(line) lines(lc(gs12) lw(vthin)) over(Semester) nofill
graph dot (asis) Avg (asis) Grade, over(Course, sort(Diff) descending) exclude0 yla(50(10)100) scheme(s1color) marker(1, ms(Oh)) marker(2, ms(plus)) linetype(line) lines(lc(gs12) lw(vthin)) over(Semester) nofill


Note: I looked at your links after thinking up my suggestion. It's a weakness of both that they don't suggest this basic kind of graph.

Threads here mentioning such plots include this, this and this.

Last but not least, references as well as a detailed example can be found here.

• Thanks for the response! I really appreciate it. I also like that graph, but I'll be honest about one thing I don't like: it's not immediately obvious to the reader which courses have negative differences vs. positive differences. Whereas with the bar you can readily see it pointing in different directions, with this you have to individually find colums where the dot and cross are switched. Any suggestions for that? May 1, 2015 at 14:34
• You could use different colours for negative and positive differences. You should show differences as line segments (see e.g. the second graph in stata-journal.com/sjpdf.html?articlenum=gr0015 As I said, plotting differences explicitly does really sit with that design. I don't think it works well with bar charts either! May 1, 2015 at 14:43
• ... does not really sit ... May 1, 2015 at 14:51
• Thanks again! The example you gave with the arrows is perfect! I agree that the structure you provided is better, it just didn't show direction as well, but your example fixes that. Much appreciated. This was my first introduction to this community and so far its awesome. May 1, 2015 at 15:09