6.10.9 Notched Boxes with Variable Width Control
Origin's box plot is highly customizable. This tutorial shows how to create a notched box plot and control the box width by another dataset.
Minimum Origin Version Required: 2015 SR0
What you will learn
- Customize box plot settings
- Use a dataset to control the box width
- Customize the axis dialog for box plots
- Add a fill area plot to a box plot as background
Steps to Control Box Width by Variable
This tutorial is associated with <Origin EXE Folder>\Samples\Tutorial Data.opj.
Also, you can refer to this graph in Origin Central. (Select Help: Origin Central menu or press F11 key , and then select Graph Sample tab, select Box Charts under the drop-down list)
- Open the Tutorial Data.opj and browse to the Box Variable Width folder.
- Activate workbook Book7, highlight columns A~F and then select Plot > Statistical: Box Chart. Next, select and delete the legend object from the graph.
- Double-click on one of the boxes to open the Plot Details dialog and go to the Box tab. Set Style to Notched Box. Select the Box Width by Parameter box and then set Box Width (%) to Number of Vehicles (in million) and enter 1.2 for Scaling Factor. Select the Outliers box. Outliers in Line is automatically checked.
- Click OK to close the dialog. Go to the Object Manager, which is docked to the right edge of Origin workspace, uncheck the last plot. And the click on the Rescale button to rescale the graph.
- The graph will look as below.
More Box Style Customization Steps
The following steps can further customize the box plot.
- To use the same color for each box, double-click on any box to open the Plot Details dialog box. Go to the Pattern tab. Set Border Color as Orange. Set Width as 1.5.
- To fill the boxes with color, expand Fill Color drop down list, and in the Single tab choose a lighter orange as below:
- Note that checking Outliers checkbox in Box tab added a Symbol tab. Use controls on this tab to customize the outlier symbol as shown below:
- To hide the 99% and 1% symbols, go to the Percentile tab and clear the symbol for both 99% and 1%. Select the 2nd symbol in the first row for Mean:
- Click OK button to accept all the changes.
More Axis Customization Steps
- To show solid grid lines between each boxes, double click on the X axis to open the Axis dialog box. Go to the Scale tab with Horizontal icon selected and set the Count of Minor Ticks to 1:
- Select the Grids tab and select the Vertical icon. Check Show under Minor Grid Lines branch and set the Style as Solid.
- Go to the Line and Ticks tab and set the tick styles for X axis (Bottom):
- Hold Ctrl key and multiple select the Top and Right icons. Check the Show Line and Ticks box to also display line and ticks of top X and right Y axis, and set the tick style to None:
- Go to the Scale tab again and select Vertical icon. Set the following:
- Go to the Tick Labels tab, make sure Left icon is selected and enter a prefix of $.
- Go to the Title tab, make sure Left icon is selected and change the text of Y axis title to Gasoline Prices.
- Click OK to close the Axis dialog.
- To add a title and footnote in the graph, right click in white area of the graph and select Add/Modify Layer Title context menu. Type US Weekly Retail Gasoline Prices. Select the title and use the Format toolbar to set font size as 26. Right click below the X axis tick labels and choose Add Text... context menu. In in-place edit mode, click I button on Format toolbar and then type Box width indicates number of vehicles in each area as a footnote. It will show in italics.
Steps to Add National Average Line and Min&Max Range
Now, we are going to add three reference lines at Y axis to show the national average and minimum-maximum range of national gasoline price.
- Double-click on Y axis to open the Axis dialog again. Go to Reference Lines tab, click Details... button to open the Reference Lines dialog.
- Click Add button at the bottom of Reference Lines dialog to add a reference line. Select this new line, set Value Type to Statistics, and enter Mean(plotdata(6, Y)) in the At Axis Value box(You can click the arrow at the end of this box to select a built-in pattern). Change the lint style to Royal and Dash, and check Show box under the Label node.
- Click Add button again to add second reference line. With this line selected at the Reference Lines at panel, set Value Type to Statistics, and enter min(plotdata(6, Y)) in the At Axis Value box. Set Line Style to Royal and Solid.
- Click Add button again to add third reference line. With this line selected at the Reference Lines at panel, set Value Type to Statistics, and enter max(plotdata(6, Y)) in the At Axis Value box. Set Line Style to Royal and Solid.
- Click OK button to close the dialog and add the reference lines to the line table.
- Enter National Average at the Label Text cell of first added line. And select the Fill To line for the second and third reference line as below:
- Click Apply button to add the reference lines to the graph. Click Details... button again to open the Reference Lines dialog, select the second line at right panel, and then set Fill Color under Pattern node to Cyan and Transparency to 90. Click OK button.
- Click OK button again to close the dialog. Go back to the graph, right-click on the label of the mean line to select Properties... from context menu to open the Text Object dialog. Enter the text below and do the format settings:
- Click OK button. At the end, you will get the final graph.