Creating Histogram with Varying Bin Width

posted in: Graphing | 2

Graph11

In Origin, histogram is plotted with equal bin width. But sometimes user wants to plot histogram with varying bin width to better illustrate the distribution of the data. This blog will show you how to do a frequency count with user-defined bin boundaries and then plot the result as a column plot with with varying column width to get the effect of histogram with varying bin width. and You can follow along with this blog by downloading the Histogram_Varying_Width zip file and open the it in Origin.

grain_worksheet

Here we have a modified set of sediment grain size data from a USGS survey, the distribution of data column C however varies considerably between different grain sizes. For this reason we’ll create a new column D and set long name to be Boundaries and enter some custom intervals- grain sizes between, 0, 25, 50, 100, 150, 200, 300, and 450 microns. After entering these values, we’ll select the grain size column C and bin our frequencies by going to Statistics>Descriptive Statistics>Frequency Counts to calculate counts in our customized bounary.

002

In this dialog, set  Specify Binning Range by to User Defined Boundaries. Then in the Binning Range Data field, click > button and pick D(Y): Boundaries. Leave the rest of the settings as their defaults and click OK. A result sheet will be added in the workbook.

frequentcount1

After closing the dialog we should see the frequency count worksheet containing the bin center, end and the counts for each bin. Add a new column and set its long name as Bin Width. Set the bin width values to based on Set Column Values dialog.

histogram_scv

Once this has been done, we’ll select the Count column (column C) and plot the column plot below.

004

It uses Bin Center column (Column A) as X position of each column and they are plotted with same width. Some may overlap since X position may be close to each other.

To modify their width to fill the entirety of our x-axis, open the Plot Details dialog and then in the Spacing tab of our plot change the widths % to be represented by Col(E) with a scaling factor of 0. When the scaling factor is set to 0, Origin will use the widths given in column E as proportional sections of the total x-range, or rather their width will fill the entirety of the x-axis between the min and max of our data.

column_width

Click OK, our column graph should appear as it does above due to the default margin settings of Origin.

 

006

We can change the axis from and to to be the from 0 to 450, our customized grain size boundary.

007

We have now created a histogram with varying bin width illustrating the disparate frequency of different particle sizes in our sediment data. With some final touches, this is how you create a variable width column graph in Origin and OriginPro. You can find the final graph on Result folder of the opj file.

 

Graph11

2 Responses

  1. I have some issues related with the new col(e). I do not understand the values what you are settin into the col(e). Can you please detail what what means? I understood from the script that the first is the sheet, then comes the column and after that [2:9]. What this mean? For ex. my boundaries I have in the the Sheet2 col(b). How the script would look like?
    Thank you for your help.

    • Hi Levente,

      You are right. User can directly use the coL(b) in Sheet2 to calculate each bin width instead of using the original col(E) on 1st sheet.

      So in Set Column Values dialog, no need to define any variable in Before Formula Script. In the Formula box, enter
      i<2? (col(B)[i]): (col(B)[i]-col(B)[i-1])

      This will count bin width based on column B. I saw the screenshot also have issues. So I will correct the blog.

      Thanks, Snow

Leave a Reply