Know Your Limits: Axis Ranges
A common question from new users of DataGraph is, “How do I specify the axis range for a graph?” In many programs, you set an axis range by specifying both a minimum and maximum value; however, a problem with this approach is that your graph may only look good for a particular data set.
DataGraph takes a more flexible approach, allowing you to control the behavior of the axis range, without having to explicitly set a minimum and maximum value. As a result, you can create graphs that can be used with new data, without having to change the axis settings.
In this blog post, we will describe the how and why of axis settings in DataGraph and present some examples to illustrate how they work.
Modifying the Axis Range in DataGraph
One of the strengths of DataGraph is that you can easily replace or modify the data used in a command. Consistent with this approach, the settings for modifying an axis range allow you to influence the range without having to explicitly specify both a minimum and maximum value. That said, if you want to restrict a graph to a particular range, you can do that as well.
To modify the default axis range open the detail view in the Axis settings.
In the detail view, you will see three settings that allow you to modify the axis ranges: (1) Include, (2) Padding, and (3) Restrict. The default values for these settings are shown below.
In the Include field, you can enter values that you want to make sure are included in the axis range. For example, if you wanted a graph to span, at a minimum, from -10 to 10, you would set Include to “-10,10”.
The Padding is set to avoid points lying directly on the axis box. When this is set to “Nice Value”, DataGraph will increase the range by a small amount beyond the minimum and maximum values in the data, and then pick the nearest tick mark.
Restrict ensures the axis does not go beyond a particular range, and requires a minimum and a maximum value. By default, Restrict is set from negative infinity to positive infinity, or all values. Restrict is applied last, and might therefore overwrite the range specified in the Include field.
Using the Include Setting
The first example comes from Ott and Mendenhall’s Understanding Statistics ( 1990), in which the last Chapter is entitled “Communicating the results of a statistical test”. In this chapter, a classic example is given, showing how the axis range can significantly impact how we interpret a given set of data.
They provide a data set containing the consumer price index (CPI) for the months Jan to Jun, plotted here using the default axis settings in DataGraph. The slope of the line seems to indicate a significant rise in the CPI over time.
Now let’s see what the graph looks like when the y-axis starts at zero.
The CPI is still rising but it does not appear as dramatic when compared to the first graph.
Including the Origin
In the first graph above, the y-axis range is based on the default settings. In the second graph, we added “0” to Include in y.
This effectively includes “0” in the dataset that the program uses to determine the axis range.
Including a Range
For the graph above where we adjusted the y-axis to include 0, let’s say we also wanted the y-axis to end at exactly 250.
Below are three ways to modify the Axis settings that would result in the above graph. The settings that have been modified from the default values are highlighted.
In Option 1, we added 230 to the Include field, which is slightly higher than the maximum value in the data. With the additional padding, the y-axis range is extended to 250, just where we want it. Option 2 sets the range at exactly 0 to 250 and removes the Padding. Option 3 sets the Include and the Restrict to the same value.
The difference in these options becomes evident when we add a another Plot command with a new data set.
Option 3 is the most restrictive approach and does not allow the axis range to grow with the new data. Option 1 and 2 are not restricted, so both will grow with the data; however, Option 1 allows the program to add padding to prevent the points from overlapping the axis box.
Using the Restrict Setting
The Restrict setting can also be thought of as a way to crop a graph or zoom in on a particular region of data. You can change Restrict in the Axis settings or interactively on the graph itself, as discussed below.
Consider the following data where a signal is being tracked over time.
Now consider the same data set with a single outlier.
Restrict can be used to focus the graphic on the data. Here we set Restrict to a maximum y-value of 25.
You can also click and drag directly on the graph. The program will then highlight the region you are selecting.
When you release the mouse, the graph will be limited to the highlighted region and the Restrict setting is modified according to your selection.
Removing the Restrict Settings
If you no longer want to restrict the range, you change the setting back to infinity (∞) in the Restrict field. DataGraph understands the infinity symbol (Option-5 on the keyboard) or you can type the variable name, ‘inf’.
As a short cut, you can also click the expand icon, as shown below. The expand icon is only visible when the graph has a Restrict setting for either the x or the y axis.
Also, hovering over an axis that has a Restrict setting will cause the following display to pop-up, containing the same icon in the top left.
This pop-up includes a bar representing the entire range of the underlying data. The portion of the bar filled in white corresponds to the data range that is shown on the graph. This is also an interactive element, in that you can drag the white bar and change the range of data displayed.
You can go back and forth between setting Restrict by typing directly in the Axis settings or zooming to a value directly from the graph.
Using Global Variables
Note that both Include and Restrict can be set using global variables. In this example, we use global variables to pull the maximum x and y (i.e., CountX and MaxY) in the data and use that in the Include settings.
Next, the data is masked on time to create the animation.
Use the links below to download the files used to create these graphs and the above animation.