Function Repository Resource:

WinLossChart

Source Notebook

Create a simple bar chart that shows the number of items in a list that fit set criteria compared to those that do not

Contributed by: Craig Cowley

ResourceFunction["WinLossChart"][{item1,item2, ,itemn}]

generates a win/loss chart based on the itemi.

Details and Options

By default, positive numbers are treated as wins and non-positive numbers are treated as losses.
ResourceFunction["WinLossChart"] takes the following options:
"WinLossPatterns"{_?Positive,_?NonPositive}patterns that correspond to wins/losses
"AxisLabels"{"Wins","Losses"}y-axis chart labels
"Colors"{Green,Red}colors of the bars

Examples

Basic Examples (2) 

Generate a list of random integers:

In[1]:=
data = RandomInteger[{-20, 20}, 20]
Out[1]=

Plot them in a win/loss chart:

In[2]:=
ResourceFunction["WinLossChart"][data]
Out[2]=

Options (3) 

The win/loss criteria can be changed with the "WinLossPatterns" option:

In[3]:=
data2 = {"Heads", "Tails", "Heads", "Heads", "Tails", "Tails", "Heads", "Heads", "Heads", "Tails", "Heads", "Heads", "Tails"};
In[4]:=
ResourceFunction["WinLossChart"][data2, "WinLossPatterns" -> {"Heads", "Tails"}]
Out[4]=

The axis labels can be changed to better reflect the contents of the chart:

In[5]:=
data2 = {"Heads", "Tails", "Heads", "Heads", "Tails", "Tails", "Heads", "Heads", "Heads", "Tails", "Heads", "Heads", "Tails"};
In[6]:=
ResourceFunction["WinLossChart"][data2, "WinLossPatterns" -> {"Heads", "Tails"}, "AxisLabels" -> {"Heads", "Tails"}]
Out[6]=

The colors of the bars can be changed:

In[7]:=
data2 = {"Heads", "Tails", "Heads", "Heads", "Tails", "Tails", "Heads", "Heads", "Heads", "Tails", "Heads", "Heads", "Tails"};
In[8]:=
ResourceFunction["WinLossChart"][data2, "WinLossPatterns" -> {"Heads", "Tails"}, "Colors" -> {Blue, Orange}]
Out[8]=

Properties and Relations (1) 

Non-numeric data is left blank in the chart produced by WinLossChart:

In[9]:=
ResourceFunction["WinLossChart"][{1, "Hello world", -1, 1}]
Out[9]=

Neat Examples (1) 

Compare two soccer teams' results over a season:

In[10]:=
tot = {w, d, l, d, w, l, w, l, d, l, d, d, w, w, l, w, w, l, w, d, l, l, d, w, w};
ars = {w, w, l, d, d, w, d, w, l, d, d, l, d, d, l, w, l, d, d, l, w, d, d, d, d};
Grid[{{"Tottenham Hotspurs FC", "Arsenal FC"}, {ResourceFunction["WinLossChart"][tot, "Rules" -> {w, l}], ResourceFunction["WinLossChart"][ars, "Rules" -> {w, l}]}}]
Out[10]=

Publisher

Craig Cowley

Version History

  • 1.0.0 – 26 February 2020

Related Resources

Author Notes

Future improvements:
Make RatioPartition[list,n] equivalent to Partition[list,n] (while ensuring the "Randomize" option still works).
Make RatioPartition[n] equivalent to RandomPartition[n] (which needs Combinatorica`).

License Information