How do I overlay two histograms in Excel?

11

The first few lines of my raw data looks like this:

0    -4.05291
0    -2.75743
0    -0.374328
1    -23.829
1    -21.5973
1    -21.0714

I want to plot the data points with 0's and 1's separately as a histogram. This wasn't that hard to do: insert -> charts -> insert statistics charts and select the relevant data and I'm done. The charts are:

enter image description hereenter image description here

The orange plot corresponds to the first distribution (indexed by 0), and the blue one corresponds to the second (indexed by 1). The problem: I want to combine the two into a single chart with two differently-coloured bars. However I can't figure out how to do it. The obvious way is to right click -> select data -> add both data series to the chart, but the histogram still shows only one set of data. The data is definitely there - if I change chart types the other series shows up - but it doesn't show up in the histogram.

How can I do this with Excel? If Excel is unable to do this: what program would be able to do it? If it matters, I'm using Excel 2016.

Allure

Posted 2018-04-04T07:49:03.747

Reputation: 231

The built-in histograms are merely toys, and are not yet capable of doing what you want. I would aggregate both sets of data in the worksheet using formulas, then plot them together in the same column chart. – Jon Peltier – 2018-04-22T14:06:10.443

Answers

5

Apparently (in Excel 2016), using a histogram doesn't seem to be possible with multiple series.

However, you can obtain the same result with a bar chart. It requires a bit more work, but it's fairly easy to do! Here is what I did.

  1. Create a "Category" table (orange), that will put the values into different ranges.
  2. Make sure the first column is a unique ID.
  3. The Max and Min columns can be filled manually, or automatically with a formula. Just make sure that there is a -9999 and +9999 (or any other big value) as the "lowest min" and the "highest max".
  4. In your data table, add the following formula (provided the orange table is named Category):

    =VLOOKUP(SUMPRODUCT(([@Value]>=Category[Min])*([@Value]<Category[Max])*(Category[Category ID])),Category,4)
    
  5. Insert a pivot table (values: count of your lines) and pivot chart as shown below:

Pivot structure

piko

Posted 2018-04-04T07:49:03.747

Reputation: 814

1Wow Excel's a lot more complicated than I thought it was. At this rate, I might as well start writing a Python program to plot this ... – Allure – 2018-04-04T21:40:40.010

4

Another option is to use the Histogram option of the Analysis Toolpak.

  1. Make sure the toolpak is enabled (if not, go to Files|Options|Add-ins)
  2. Split your data into columns (one for your '0' points and one for '1') points
  3. Create bins in another column (Excel will do this automatically but you need to be sure both series have the same bins)
  4. Go to Data|Data Analysis|Histogram
  5. Select your '0' points and the bins, then put the output on a 'new worksheet ply'
  6. Repeat for the '1'
  7. Combine those two tables and plot the result

Input Data Output chart

Peter Hull

Posted 2018-04-04T07:49:03.747

Reputation: 141

1

Use Past3: https://www.techworld.com/download/office-business/past-314-3330821/

It is a free and powerful tool for doing statistical analysis and making graphical illustrations. I needed to make combined histograms and this program made the process super easy. I struggled with Excel for quite some time but then found Past3 and have been using that for most of my illustrations since then. Here I combined three sets of data in one histogram so it looks a bit crazy with the way it overlaps the colors but still looks good and very intuitive:
example image
With two colors/sets it looks really good.

user919388

Posted 2018-04-04T07:49:03.747

Reputation: 19

0

You are very close to your answer. The only thing that you have yet to do is select the series in your second graph (click the graph, then click the bars and make sure all bars are selected (see picture 1). Press Ctrl+C and then click the first graph and press Ctrl+V. I did the same as you did with random data and I found this (see picture 2):

Bars selected

End result

The red bars are added by copying and pasting.

Michthan

Posted 2018-04-04T07:49:03.747

Reputation: 466

For some reason this doesn't work for me - I end up copying the entire chart (not just the series, but the chart) and after pasting I get two of the original chart. Is this what you mean when you say "all bars are select"? https://imgur.com/a/7IhCn

– Allure – 2018-04-04T10:30:23.907

It's because Michthan is using a standard bar charts, while you're using a histogram chart. As far as I know, histograms can only work with only 1 set of data, not 2 like in your example. – piko – 2018-04-04T12:20:43.600

@piko, I just go to data analysis and select histogram and this is what comes out.. – Michthan – 2018-04-04T12:39:20.573

Hmm strange. What Excel version are you using? I tried in Excel 2016, and like Allure, it creates a new chart. I made sure to select only the bars, not the chart, before copying. – piko – 2018-04-04T12:43:34.547

@piko, still on 2010 version, so can't help you with 2016.. – Michthan – 2018-04-05T05:59:48.427

1Learn something new every day. I didn't realize I could copy a set of bars from one chart and paste them into another. I wonder when they added that feature. – Jon Peltier – 2018-04-22T14:10:00.240

1Actually, you can't select just one series and copy it. Copying one series really copies all series in the chart, and pasting then pastes all the data into the second chart. In this case it works because the copied chart has only one series. Damn, that would have been cool. – Jon Peltier – 2018-04-22T14:45:31.533

0

Follow Peter Hulls instructions however do NOT use the histogram function, this only works for 1 set of data. You must use a bar chart. 1. get data analysis function 2. use to make histogram, selecting data and bins(the bins u choose and must be the same for all) 3. repeat step 2 for all the data you need 4. copy and paste the same bin set you used for everyone of the data sets over to a new sheet once 5. copy and past the frequencies over for each set 6. go to insert, and select bar graph 7. select data 8. add each series as separate series 9. finally select the bins as the horizontal and you should have a histogram but created as a bar graph

Alex

Posted 2018-04-04T07:49:03.747

Reputation: 1