# 6.1.2 Creating a Graph

## Summary

Origin provides templates library. You can create and modify templates by your own and add to the collection. Creating a graph in Origin is as simple as selecting the desired data and then selecting a template from a menu or from the graphing toolbars. The Plot Setup dialog offers more flexibility in creating plots, such as plotting data from multiple books or sheets.

Starting with Origin 2016, a more powerful "cloneable" template has been added. These templates are designed for "smart plotting", meaning you can clone a graph with a complicated layer hierarchy or with source data that cannot be specified by simple selection. See this tutorial on plotting from user-defined graph templates to learn how to save and use both standard and cloneable templates.

This tutorial will show you how to:

• Select data in a worksheet and quickly create a plot
• Change X/Y input of the data plot with context menu
• Add data to or remove it from an existing graph
• Use Plot Setup to plot data from multiple sheets
• Plot groups of plots by label

Minimum Origin Version Required: Origin 2016 SR0

## Create a Plot Quickly by Selecting Data

1. Click the Import Multiple ASCII button to open the dialog for import multiple ASCII, select the files S15-125-03.dat, S21-235-07.dat and S32-014-04.dat from \Samples\Import and Export\ and click Add File(s) to add three files to the lower panel.
2. Make sure Show Options Dialog is checked, click the File Name column header to sort the files, click OK.
3. In the Import and Export: impASC dialog Change Import Options: Import Mode to Start New Sheets. Expand the (Re)Naming Worksheet and Workbook node and change settings so that only the sheet gets renamed.
4. Click OK. The imported results should appear as below:
5. Make the third worksheet, S32-014-4, active. To create a three layer graph, highlight the three Y columns, Delta Temperature, Magnetic Field, and Position, and then select Plot > Basic 2D: 3Ys Y-YY. Note: There is no need to highlight the Time column, as Origin will automatically plot the Y columns against the associated X column in the worksheet.

## Change X/Y Data of the Plot

Use the same worksheet from the previous example.

1. Highlight column B and click the Line button to generate a line plot.
2. Right click on the data plot and point to the Change Y context menu, then select column C (Magnetic Field) in the fly-out.
3. You may see a reminder message about rescaling the graph to show all data. Choose Yes and click OK so that the updated plot will be auto-rescaled.
4. The plot will update as shown below:
 With this context menu, you can change the X or Y data of the current plot to be another column in current sheet. This column will be any column other than the current X or Y data column from the same worksheet, regardless of column designation. You are also allowed to use the Change Worksheet context menu to change the current X and Y data to be the columns with same column index in another worksheet of current workbook, regardless of column designation and column short name.

Note: You can also use the Layer Contents or Plot Setup dialog to change the input data.

## Add Data to an Existing Graph and Update Legend

### By Drag and Drop

1. Go back to the book with the three sheets of data from the above example.
2. Highlight the Delta Temperature column (Column B) from the first sheet and then select Plot > Basic 2D: Line to create a line plot.
3. Go back to the workbook. For each of the remaining two sheets, select the Delta Temperature column and position the cursor at the edge of the column until you see the cursor change to .
4. Then you can drag-and-drop the column into the graph page. Another curve will be added to the current layer.
5. After adding the other curves, double-click on the layer icon to open the Layer Contents dialog. You need make sure that the Double click to open Plot Setup option doesn't been selected in the Context menu(expanded by right-clicking on Layer icon) firstly.
6. In the Layer Contents dialog, hold Ctrl key to select the three items listed in the right panel, then click Group button to group the three plots.
 You can also use the Plot Setup dialog which can be opened by selecting Plot Setup... from the context menu above to do the same setting, Please refer to Plotting using Plot Setup for more information.
7. Click Ok button to close the dialog. Grouping the plots allows for quick creation of presentation-ready graphs, because each selection in the group is assigned a differentiating set of plot attributes (line color = black, red, green; symbol shape = square, circle, triangle; etc...).
8. Select Graph: Legend: Update Legend... to open the legendupdate X-Function dialog. Set the Auto Legend Translation Mode to Custom. Enter @WS for Legend Custom Format.
9. Click OK and the legend will now contain the worksheet name for each data plot.
10.  The default plot type of the drag and drop plot is Current, which is the same as the current active plot. However you could change the default option. To do this, click Preference: Options and go to the Graph tab, and change the setting of Drag and drop plot drop-down menu.

### By Layer Contents Dialog

The Layer Contents dialog box is useful primarily for adding or removing data plots from the graph layer. Starting with Origin 2016, you can switch layers without closing the dialog box, making it easier to add plots to, or remove plots from, a multi-layer graph. To demonstrate, we will return to the 3-layer graph that we created in the first exercise in this tutorial:

In the first exercise, we plotted data from sheet S32-014-04. In this exercise, we will swap the data from sheet S32-014-04 with data from sheet S21-235-07.

1. Right-click on the layer 1 icon in the upper-left corner of the graph window and choose Layer Contents.
2. In the dialog box that opens, click the drop-down list in the upper-left corner and select Worksheets in Folder.
3. Right-click on the left-panel headings, clear Book Name and select Sheet (if not already displaying) so that you can see which worksheets contain which workbook datasets, then click on the Sheet heading to sort datasets by sheet name.
4. In the right-hand panel of Layer Contents, select Delta Temperature from sheet S32-014-04 and click the Remove Plot button to remove the plot from graph layer 1.
5. In the left-hand panel, select Delta Temperature from sheet S21-235-07 and click the Add Plot button , then click Apply to add the new plot to layer 1. You have now swapped one dataset for another.
6. Click the Layer(1) button at the top of the dialog and choose Switch Layer > 2. Layer 2.
7. Repeat the process of removing the existing Magnetic Field dataset from layer 2 and replacing it with the Magnetic Field dataset from sheet S21-235-07, then click Apply.
8. Click the Layer (2) button and choose Switch Layer > 3.Layer 3 and repeat the process of swapping the Position dataset in sheet S32-014-04 with the Position dataset in sheet S21-235-07, then click Apply and close the dialog box.

## Create a Plot using Plot Setup

The Plot Setup dialog box is useful for a variety of plotting tasks, including creating graphs, modifying the plot type, adding plots to or removing plots from the graph, grouping or ungrouping plots, and editing the plot range.

1. Return to your workbook and ensure that no data are selected. It doesn't matter which worksheet is active; what is important is that no columns are highlighted.
2. Select Plot > Basic 2D: 4 Panel from the menu. When no data are selected, Origin opens the Plot Setup dialog, allowing you to choose the data you wish to plot.
3. Expand the top panel by clicking the button. Hold down Ctrl key to highlight the three worksheets. Alternatively, you can just click and drag your selection so that all three worksheets are highlighted.
4. In the middle panel, common columns in all three sheets are displayed. In this case, all three sheets have similar data with matching column names. Click the button at top-right of this panel to show the available plot columns listed with similar column long name. This mode is easier because you don't have to check the X and Y designation check boxes.
5. Open the bottom panel of the dialog, the Plot List, if it is not already visible. Layer 1 is highlighted. Select Delta Temperature in the middle panel, and then click the Add button. Since you already selected the three worksheets in Step 3, this will add all Delta Temperature columns from the selected worksheets to layer 1.
6. Repeat these steps to add all Magnetic Field columns and all Position columns into Layer 2 and Layer 3, respectively.

Note that in each layer, the three data plots are automatically grouped.
7. Click the OK button to create the graph.
8. You'll note that the default legend that is created for each layer is not particularly helpful. The Origin graph legend object is highly customizable, so before we go further, we will modify the default legend. Right-click on any of the legend objects and select Legend: Update Legend from the shortcut menu.
9. In the dialog box that opens, do the same settings at step 8 of the section By Drag and Drop. Note that the Legend Custom Format syntax @WS is LabTalk Substitution Notation for the name of the worksheet containing the data for each line plot.
10. We have one extra (empty) layer on the graph page. To delete that layer, click on it once to select it then press the Delete key on the keyboard. Take care not to delete the graph window as we will use it in the next section of this tutorial.
 In the graph above, the legend for each layer is same with each other. You can delete two of them. Or do settings below in the Legend Update dialog, to just show one legend for whole graph window. Once the settings are applied, you can press Ctrl + double-click on the legend text to do further in-place edits; or you can right-click on the legend box to select Properties... from context menu and do further advanced editing in the Text Object dialog.

## Plot Grouped Data As

When your data includes a column of categorical data, or multiple columns characterizing some sort of nested sub-grouping of data, just as the data below

then you might want to plot your data as:

### Trellis Plot

Beginning with Origin 2017, you have introduced the Trellis Plot which has one layer but with M X N panels.

1. New a workbook. Click the button to import the file <Origin program folder>/\Samples\Statistics\2010.dat into the active worksheet.
2. Highlight col(H)~col(J) to select Plot> Categorical : Trellis Plot menu. The dialog plot_group will pop up. Select col("City") as horizontal group variable and col("Gender") as vertical group variable for the panels.
3. Click OK button to plot the graph. Double-click on the X axis to open the Axis dialog, set From and To for horizontal axis to -10 and 90 in the Scale tab. You will get the graph as below:
4. Just as you can see, this trellis plot has only one layer but with six panels(2×3):2 rows represent the variable "Gender", Female and Male; three columns represent the variable "City", A, B, and C.

### Grouped Box Plot

Besides the trellis plot, you can also plot these kind of data as a grouped box/column plot.

1. Active the source worksheet above again. Highlight col("Salary") to select Plot > Categorical : Grouped Box Charts - Indexed Data menu to open the dialog plot_gdoxindexed. Select col("Gender") and col("City") as Group Columns.
2. Click OK button to plot the graph.
3. Just as you can see, the data col("Salary") has been plotted as a grouped box charts: Two groups by "Gender", Female and Male; within these two groups, three subgroups by "City" , A, B, and C.

## Plot Graphs by Label

Origin offers a plotting option, Multiple Panels by Label, that allows you to create a multilayer graph, each layer of which contains multiple plots, identified by the same label.

1. Open the file Samples\Graphing\Automobile Data.ogw (Hint: Make sure that your Open files filter is set to Workbooks(*.ogw)).
2. Click on top left corner of the worksheet to select the entire sheet. Select Plot > Basic 2D: Multiple Panels by Label to open the plotbylabel dialog.
3. Set the dialog options as following, and click the OK button to create the graph.

The graph should look like this: