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?
Thanks for any help you can give
// 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 °F"); // Concatenate temperature vectors // into a 2x2 matrix heights = phoenix ~ seattle; // Draw the graph plotBar(myPlot, labels, heights);
1 Answer
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 };
plotAddBoxErrorBars(labels, heights, se);
proc (0) = plotAddBoxErrorBars(labels, heights, se);
local box_xs;
box_xs = calcBoxCenters(2, cols(heights));
plotAddErrorBar(box_xs, vec(heights), vecr(se));
endp;
proc (1) = calcBoxCenters(nlabels, nboxes);
local box_width, idx, x;
box_width = 0.5;
x = seqa(1, 1, nlabels);
idx = seqa(x[1]-box_width/2+box_width/(nboxes*2), 2*box_width/(nboxes*2), nboxes);
retp(vecr(idx+(x-1)'));
endp;
Your Answer
1 Answer
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 };
plotAddBoxErrorBars(labels, heights, se);
proc (0) = plotAddBoxErrorBars(labels, heights, se);
local box_xs;
box_xs = calcBoxCenters(2, cols(heights));
plotAddErrorBar(box_xs, vec(heights), vecr(se));
endp;
proc (1) = calcBoxCenters(nlabels, nboxes);
local box_width, idx, x;
box_width = 0.5;
x = seqa(1, 1, nlabels);
idx = seqa(x[1]-box_width/2+box_width/(nboxes*2), 2*box_width/(nboxes*2), nboxes);
retp(vecr(idx+(x-1)'));
endp;