Accelerating the pace of engineering and science

# Documentation

## Overlay Bar Graphs

This example shows how to overlay two bar graphs.

Define series1 and series2.

```x = [1,3,5,7,9]; % place bars at these points along x-axis
series1 = [10,25,90,35,16];
series2 = [7,38,31,50,41];
```

Create a bar graph of the data in series1. Set the bar width to 0.5. Set the bar color to dark blue by setting the FaceColor property to an RGB color value.

```figure
width1 = 0.5;
bar(x,series1,width1,'FaceColor',[0.2,0.2,0.5])
```

Use the hold function to retain the first graph. Plot the second bar graph over the first bar graph using a smaller bar width. Specify a different RGB color value for the FaceColor and EdgeColor properties of the second bar graph.

```hold on
width2 = width1/2;
bar(x,series2,width2,'FaceColor',[0,0.7,0.7],...
'EdgeColor',[0,0.7,0.7])
hold off

legend('First Series','Second Series') % add legend
```

The figure contains two bar graphs. MATLAB® plots the dark blue bars behind the light blue bars since the dark blue bars are plotted first. The order of the plotting commands determines the stacking order of the bars.