Unstack and Stack Columns

posted in: Data Handling, Worksheet | 0

Sometimes your imported data may not be able to be used directly to plot certain graph or do certain analysis. Origin provides multiple ways to transform your data. This post will show you an example of unstacking columns so as to plot multi-panel graphs based on labels of columns.

Please download the opj file: Unstack&Stack_Cols

Go to Folder1 to play with sample data:



XY data is in Col(A) and Col(B), and indexing or grouping information is in Col(C) and Col(D). We want to plot a multi-panel graph, each Treatment in one panel.

First, let’s unstack XY data into categories of Gender and Treatment at different columns.

Highlight Col(A) and Col(B) in the worksheet, then go to menu Worksheet: Unstack Columns: Open Dialog. Add Group Column(s) to be D(Y) : Treatment and C(Y) : Gender successively. And select Put Grouping Info. to be User Defined Parameters so that Long Name from group columns will be appended on output columns.

The order of Group columns controls the level of category, and it can be adjusted using these buttons DOC-2358_3. If you have other columns to include in the unstacked worksheet, just check the Include Other Columns(s) checkbox under Options, and select data similarly.

Click OK, and unstacked data will be appended in a new worksheet, and labels will append on newly added header rows.



Then the data will be ready for example for a multi-panel scatter plot. Just highlight entire worksheet, and go to menu Plot: Multi-Panel: Multiple Panels By Labels, and choose settings as following:

Then, just further customize Axis, Layer and legend to have a graph as following. Please go to Result folder to view as well.


Besides, if your data doesn’t have indexing columns and you want to use row indexing as grouping, then you can use the x function colsplit to unstack columns. Run following script:

It will open the following dialog, where you can either unstack By Every Nth Row, or By Sequential N Rows.




Stacking columns from menu Worksheet: Stack Columns is the the reverse operation of unstack columns.


Leave a Reply