 # Error bars in bar graphs

The GAUSS blog has a nice example of putting error bars on a single column of values in a bar graph.  Is there an easy way [other than trial and error with plotAddErrorBar()]  to put error bars on side-by-side bar graphs? Pasted below is the code from an example in the GAUSS 20 help file under 'plotBar'. Just for the sake of argument, let's say the standard errors associated with the temperatures are {5 8, 8 10};

How could we re-do this plot with error bars?

```// Create 2x1 numeric vectors
seattle = { 47, 70 };
phoenix = { 68, 105 };

// Create 2x1 string labels
labels = "January" \$| "June";

// Declare 'myPlot' to be a plotControl struct
// and fill with defaults settings for bar plots
struct plotControl myPlot;
myPlot = plotGetDefaults("bar");

// Create legend
leg_text = "Phoenix" \$| "Seattle";
plotSetLegend(&myPlot, leg_text, "top left inside");

// Set legend border to zero pixels wide
plotSetLegendBorder(&myPlot, "gray", 0);

// Set Fill to two different fill patterns
// and 100% opacity
plotSetFill(&myPlot, 12|13, 1);

// Use HTML to create the degrees symbol
plotSetYLabel(&myPlot, "Temp &deg;F");

// Concatenate temperature vectors
// into a 2x2 matrix
heights =  phoenix ~ seattle;

// Draw the graph
plotBar(myPlot, labels, heights);```

0

That is a great question!

I made a couple of little procedures that will do this for you. I'm happy to discuss the details if you have questions. Otherwise, here is the full example: ``````// Create 2x1 numeric vectors
seattle = { 47, 70 };
phoenix = { 68, 105 };
denver = { 32, 85 };

// Create 2x1 string labels
labels = "January" \$| "June";

// Declare 'myPlot' to be a plotControl struct
// and fill with defaults settings for bar plots
struct plotControl myPlot;
myPlot = plotGetDefaults("bar");

// Create legend
leg_text = "Phoenix" \$| "Seattle" \$| "Denver" \$| "";
plotSetLegend(&myPlot, leg_text, "top left inside");

// Set legend border to zero pixels wide
plotSetLegendBorder(&myPlot, "gray", 0);

// Set Fill to two different fill patterns
// and 100% opacity
plotSetFill(&myPlot, 12|13, 1);

// Use HTML to create the degrees symbol
plotSetYLabel(&myPlot, "Temp °F");

// Concatenate temperature vectors
// into a 2x2 matrix
heights =  phoenix ~ seattle ~ denver;

// Draw the graph
plotBar(myPlot, labels, heights);

se = { 5 8,
8 10,
30 15 };

proc (0) = plotAddBoxErrorBars(labels, heights, se);
local box_xs;

box_xs = calcBoxCenters(2, cols(heights));
endp;

proc (1) = calcBoxCenters(nlabels, nboxes);
local box_width, idx, x;

box_width = 0.5;

x = seqa(1, 1, nlabels);

idx = seqa(x-box_width/2+box_width/(nboxes*2), 2*box_width/(nboxes*2), nboxes);

retp(vecr(idx+(x-1)'));

endp;`````` aptech
1,728

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.