GRAPH Instruction |
GRAPH( options ) number hfield vfield
# series start end symbol choice (one for each series, omit when using SERIES option)
GRAPH produces high-resolution time series graphs. It has a large number of options, which permit you to control most aspects of the presentation.
Wizard
Use the Data/Graphics—Graph Wizard. Note that in order to keep the Wizard from getting too complicated, some of the GRAPH options have been omitted in the wizard. To further customize your graph, you can edit the GRAPH instruction generated by the wizard by adding the desired options.
You can also create time series plots , histogram plots, and box plots from the Series Window. Select (highlight) one or more series in the window and click on one of the graphing buttons on the toolbar. Those are for quick looks—they don't generate instructions.
Positioning
If you’re using SPGRAPH to put multiple graphs on a single page, by default, the fields are filled by column, starting at the top left (field 1,1). If you want to fill a particular field instead, use either the combination of COL and ROW options or hfield (for the column) and vfield (for the row) parameters.
Parameters
number |
number of series to graph (1 by default). If you use the SERIES option, this is ignored, and the number of elements in the array of SERIES is used. |
hfield, vfield |
See “Positioning” above. |
Supplementary Cards (one per series, omit if using SERIES option)
series |
the series to be graphed. |
start , end |
(Optional) the range to graph. If you have not set a SMPL, this defaults to the defined range of series. start and end can be different for each series in the graph. |
stylenum |
(Optional) An integer value (1 through 30) specifying the line, fill, or symbol style to use for series. By default, RATS uses different colors (or patterns for black and white output) for each series. You can choose from the default styles provided by RATS, or you can use style sheets to customize attributes such as color or gray scale levels, line thickness, fill patterns, and more. A style number over 30 is "wrapped" to a number in range (41 is the same as 11). |
General Options
PATTERNS/[NOPATTERNS]
This chooses the way you want GRAPH to distinguish among the series. RATS normally uses different colors, and will automatically switch to black and white patterns if you print the graph on a black and white printer. If you want to see on the screen (approximately) how the black and white hard copy will appear, use the option PATTERNS—RATS will display the series with patterns rather than colors. Note that you can also switch between patterns and colors after displaying the graph by using the toolbar icon on the graph window.
WINDOW="window title" [HEADER or FOOTER option value]
When working in interactive mode, the WINDOW option allows you to set a title for the graph window that will be associated with the graph. By default, graph windows are titled using either the HEADER or FOOTER strings; if you have neither of those, nor WINDOW, they are “Graph.01,” “Graph.02,” etc.
FOOTER="label" [unused]
Adds a left-justified label in the lower left corner of the graph. To prevent a footer from getting too wide, you can use the characters \\\\ to insert a line break.
FRAME=[FULL]/HALF/NONE/BOTTOM
[BOX]/NOBOX
FRAME controls the box displayed around the outside of the graph. HALF displays the frame only to the left and below the graph, omitting the top and right sides. BOX/NOBOX is an older option for controlling the box (frame) which is superseded by the more flexible FRAME. NOBOX is equivalent to FRAME=NONE.
SMPL=Standard SMPL option[unused]
Omits from the graph any observations where SMPL series or expression is zero.
ROW=row number in SPGRAPH array
COL=column number in SPGRAPH array
When adding a graph to an SPGRAPH array, you can use these options to indicate the row and column in the array in which to place the graph.
HEIGHT=height of graph in inches
WIDTH=width of graph in inches
These options specify a fixed size for the graph. You must use both options together to have RATS display the graph at the specified size. The "FIX" toolbar button will be on, freezing the proportions of the graph. RATS maintains the size if you print or save the graph. Resizing the window will resize the graph proportionally. Use the "Unfix" button if you want to change the proportions. To specify sizes in centimeters, use the %CM() function to convert centimeters to inches.
STYLE=[LINE]/POLYGON/BAR/STACKEDBAR/OVERLAPBAR/VERTICAL/STEP/SYMBOL/MIDPOLYGON/FAN/DOTS/SPIKE
LINE is a simple line graph. It draws a line from one point to the next.
POLYGONAL draws a line from one point to the next, and paints the region between this line and the X-axis (or bottom of the graph if the minimum is greater than 0). Recommended only when graphing a single series.
BAR draws a separate rectangle for each data series at each entry. If you are graphing more than one series, you can’t really use BAR for more than about 100 data points, as the bars get too thin—use SPIKE instead.
With the STACKED option, RATS stacks the bars for all the series at a given time point into a single large rectangle. Positive values stack up away from zero, while negative ones stack down away from zero.
OVERLAP is similar to BAR, except that the bars overlap somewhat. This allows it to be used with more data points or series than the simple bar graph. Since this paints the bar for the second series over part of the first series, the third over part of the second, and so on, this style works best when the first series is the largest and the last the smallest.
VERTICAL connects all values at a given time period with a vertical line, with hash marks at all the values. You can use this for high/low/close plots or for plotting confidence intervals.
STEP is similar to LINE except instead of drawing a line directly from one point to the next, it draws horizontally to the new “x” position, then vertically to the new “y” position.
SYMBOLS is similar to LINE except that it draws symbols at regular intervals along the line. This may produce a better printed copy of the graph if you have a number of intertwined series.
MIDPOLYGON is like POLYGON, except that the polygons are centered on tick marks (similar to BAR), rather than centered between tick marks
FAN creates a fan chart, filling in the gap between series with a set of shaded fill patterns, getting lighter towards the outside. Can be used to fill space between two series, but is most useful with five or more series.
DOTS plots each data point with a large dot.
SPIKE is similar to a bar graph, but uses narrow spikes rather than wide bars.
SERIES=VECTOR of SERIES to be graphed [unused]
SYMBOLS=VECTOR of INTEGERS supplying style numbers for SERIES [unused]
The SERIES option provides a convenient way to graph all of the series stored in VECTOR of SERIES. Omit the supplementary cards when using the SERIES option. When using SERIES, you can also use SYMBOLS to supply a VECTOR of INTEGERS with the style numbers you want to use for the corresponding series.
Graph Header Options
HEADER="header string" [unused]
The header is centered above the graph. Although RATS will accept a string of up to 256 characters, it may not be possible to fit such a long string on the page. To get a very long header to fit, you may have to change the header font size (which is drawn in 24 point boldface by default) using GRPARM. You can also insert line breaks in the string, by including the characters \\\\ at the point where you want the line break.
SUBHEADER="subheader string" [unused]
The subheader is centered above the graph and below the header. By default, it is presented in 18 point italics. As with the HEADER option, you can use the characters \\\\ to insert a line break.
Time Axis Options
HLABEL="label" [unused]
HLABEL is centered below the graph and below the entry labels (if any). You can use the characters \\\\ to insert a line break.
[TICKS]/NOTICKS
NOTICKS suppresses the tick marks and entry labeling on the time axis.
[DATES]/NODATES
NUMBER=labeling number assigned to first entry plotted [unused]
By default, GRAPH labels entries with dates (if possible) on the horizontal axis. How RATS represents dates depends on the font sizes (controlled with GRPARM), the number of observations, and the size and shape of the graph. With a relatively short series of daily data, GRAPH will probably use full month names with dates at each entry. With long annual series, it may only label one out of every five years. Year or month labels are centered under entries covered by that date.
With NODATES, GRAPH labels graphs with entry numbers. You can use NUMBER (with NODATES) to use a number other than the entry number for the first observation. For instance, RATS stores autocorrelations with the 0 lag in entry 1. To label them correctly, use the options NODATES and NUMBER=0.
SHADING=series with non-zero elements in ranges of entries to be shaded for emphasis
GRID=series with non-zeros at entries for vertical grid lines [unused]
GRID and SHADING are alternative options for highlighting sets of entries. GRID merely puts a vertical grid line at each entry for which the series has a non-zero value. SHADING is a little more complicated: any block of consecutive non-zero entries will produce a lightly shaded region on the graph covering those entries.
XLABEL=VECT[STRINGS] for labeling points on the time axis
This overrides the standard date or entry labels with the supplied labels. These will be spaced equally across the x-axis. If you don’t have one label per data point, be very careful to ensure the labels line up correctly with the data.
Vertical Axis Options
SCALE=[LEFT]/RIGHT/BOTH/NONE
The vertical scale indicates the range of values graphed. You can place it on either or both sides of the graph, or omit it completely.
VLABEL="vertical scale label" [unused]
This places the vertical scale label on the SCALE side(s) of the graph. The label will appear to the outside of the tick marks, centered vertically.
LOG=base for logarithmic scale [not used]
If the LOG option is used, the data are plotted on a log scale. The base really affects only the levels that get labeled, which will always be powers of the base. The values of 10, 2, 4 and 5 are most likely to work well.
MAX=maximum value of plot range [maximum]
MIN=minimum value of plot range [minimum]
Use these (alone or together) to set upper and lower bounds on the vertical axis. A common use is MINIMUM=0.0 to set 0 as the base value. If data go outside this range their values are clipped: the plot range is not extended to cover them. When this happens, any out-of-range value is replaced by the boundary value.
PICTURE="picture code for (vertical) axis labels"
Picture code to set formatting of axis label numbers. For instance, PICTURE="*.##" will show the numbers with two digits right of the decimal. By default, GRAPH chooses the shortest representation that can show all values accurately.
[AXIS]/NOAXIS
With NOAXIS, GRAPH will not draw the horizontal axis line even if the zero value lies within the range of values in series.
VTICKS=maximum number of vertical tick marks [9]
VTICKS=VECTOR of specific locations for tick marks
EXTEND/[NOEXTEND]
VGRID=VECTOR with values for grid lines across from the vertical axis [unused]
RATS normally marks the vertical axis with small tick marks. VTICKS can either set the maximum number of labeled tick marks on the vertical scale, or you can provide a VECTOR with specific locations. The EXTEND option draws dotted lines across the full width of the graph (RATS ignores EXTEND for overlay/two-scale graphs). VGRID accepts a VECTOR of vertical-axis values at which horizontal lines will be drawn going across the graph.
Two-Scale (Overlay) Graph Options
Two-scale graphs are created with a single GRAPH instruction, using OVERLAY and the related options.
OVERLAY=[LINE]/POLYGON/BAR/STACKEDBAR/OVERLAPBAR/VERTICAL/STEP/SYMBOL/MIDPOLYGON/FAN/DOTS/SPIKE
OVERLAY makes the graph a two-scale graph, and specifies the style to use for the overlaying series (right-side scale series). See STYLE for details on the styles.
OVSAMESCALE/[NOOVSAMESCALE]
You can use OVSAMESCALE to force both the regular and the overlay series to share a common scale. They will just be shown in different styles.
OVCOUNT=Number of series for right-side scale [1]
The last Number series listed on the supplementary cards are graphed using the right-side scale. The other series are graphed using the left-side scale.
OMAX=Maximum value for right-side scale [largest value]
OMIN=Minimum value for right-side scale [smallest value]
OVLABEL=label for right-side scale
OMAX and OMIN allow you to set the maximum and minimum values, respectively, for the right-side scale. These function like the MAX and MIN options (which control the left-side scale when doing a two-scale graph). OVLABEL allows you to supply a label for the right-side scale.
[OVKEY]/NOOVKEY
You can use NOOVKEY to eliminate the key for the overlay series, if the meaning is either obvious, or provided using the labels.
OVRANGE=fraction of overlap of regular and overlay scales [1.0]
OVRANGE offsets the left and right scales vertically, so that the STYLE side and the OVERLAY side are each graphed using only a portion of the available vertical space. With the default value of 1.0, both scales overlap fully (share the same vertical space). With OVRANGE=0.5, each scale will use only half of the total space.
Key Options
KEY=[NONE]/UPLEFT/UPRIGHT/LOLEFT/LORIGHT/ATTACHED/ABOVE/BELOW/LEFT/RIGHT
KEY controls the placement of the key for the graph. The choices are:
NONE |
no key |
UPLEFT |
key in upper left corner, inside the graph box |
UPRIGHT |
upper right corner, inside |
LOLEFT |
lower left corner, inside |
LORIGHT |
lower right corner, inside |
ABOVE |
centered above the graph (and any HEADER and SUBHEADER). |
BELOW |
centered below the graph, and below any X-axis labeling |
LEFT |
left side, centered vertically, outside graph and Y-axis labeling |
RIGHT |
right side, centered vertically, outside graph and Y-axis labeling |
ATTACHED |
used with LINES and SYMBOLS styles, this puts the labels inside the graph near the lines or symbols, at positions where the association of a line with the labels as unambiguous as possible. |
KLABEL=VECTOR of STRINGS for KEY labels
By default, RATS labels the KEY with the names of the series. Use KLABEL to supply your own labels. You can create the VECTOR[STRINGS] ahead of time, or enter it using the ||..|| matrix notation.
The order of labels in the VECTOR should match the order of the supplementary cards. You can use
\\\\ in a string to put a line break in the string.
[KBOX]/NOKBOX
This controls whether or not a box (border) is drawn around the key.
KHEIGHT=height of key box (between 0 and 1)
KWIDTH=width of key box (between 0 and 1)
By default, RATS tries to find the most efficient arrangement for the key, given the number of series in the key, its position, the setting of the GRPARMKEYLABELING parameter, and so on. KHEIGHT and KWIDTH allow you to control the size and proportion of the box by specifying the height and width of the box as a fraction of the graph’s overall height and width. You must specify both options.
[KSAMPLE]/NOKSAMPLE
NOKSAMPLE eliminates the sample line styles, colors, or fill patterns from the key, leaving only the labels.
Notes
RATS leaves missing values out of the graph. For a line graph, a dotted line connects the points on either side of the missing data point.
For graphing a large number of series on a single graph, you may want to collect the series into a VECTOR of SERIES and supply that variable using the SERIES option rather than using supplementary cards You can also use LIST and CARDS to automate the supplementary card list.
Examples
GRAPH has nearly 50 options, so it's impossible to demonstrate all of them. We show a few examples below.
This uses KEY=ATTACHED. This works well here because the series are well-separated. If the series are intertwined, it may be hard to find a good location to put an identifier string. If you have a problem, use one of the other positions.
cal(m) 1973:1
open data exdata.rat
data(format=rats) 1973:1 1989:10 pc6it pzunew exritl
*
* Transform and normalize the data series
*
set italcpi = 100*log(pc6it/pc6it(1973:1))
set uscpi = 100*log(pzunew/pzunew(1973:1))
set exrat = -100*log(exritl/exritl(1973:1))
*
graph(header="Figure 19.2",key=attached,klabel=||"Italy CPI","US CPI","Ex Rate"||) 3
# italcpi
# uscpi
# exrat
This uses the GRID option to put a vertical dividing line separating the actual data from the forecasts.
open data haversample.rat
calendar(m) 1978
data(format=rats) 1978:1 2007:4 fcm30 ftbs3
*
* FCM30 = Yield on 30 Year Treasury Bonds
* FTBS3 = Yield on 3 Month Treasury Bills
*
* Forecast twelve periods out-of-sample using simple smoothing model
* with fixed parameter of .8. Append the forecasts to the series for
* ease in graphing.
*
esmooth(alpha=.8,forecast=ftbs3,steps=12) ftbs3
esmooth(alpha=.8,forecast=fcm30,steps=12) fcm30
*
* Graph with more informative key labels, showing the last six months of
* actual data, followed by the forecasts. Include a vertical line at
* 2007:4.
*
graph(grid=(t==2007:4),key=below, $
klabels=||"30 Year Bonds","3 Month Bills"||) 2
# fcm30 2006:11 2008:4
# ftbs3 2006:11 2008:4
This uses the same color (2=blue by default) for the upper and lower bounds.
open data auto1.asc
cal(q) 1959:1
data(format=prn,org=columns) 1959:1 1973:3 x2 x3 y
*
* Tests and graphs based upon recursive estimation
*
rls(sehist=sehist,cohist=cohist,sighist=sighist,$
csum=cusum,csquared=cusumsq) y 1959:1 1973:3 rresids
# constant x2 x3
*
* rstart is the first observation without a perfect fit
* (In general, you could get this by %regstart()+%nreg).
*
compute rstart=1959:4
*
* This graphs the recursive residuals with the upper and lower two
* (recursively generated) standard error bands.
*
set lower = -2*sighist
set upper = 2*sighist
graph(header="Recursive Residuals and Standard Error Bands") 3
# rresids
# lower / 2
# upper / 2
This demonstrates the use of the @DISAGGREGATE procedure, attempting to reconstruct quarterly GDP from annual numbers using industrial production as a related variable. The graph shows the actual data, the reconstructed data and IP. Since IP is in a completely different scale, this uses the OVERLAY option to give it a separate scale.
*
* Example of the use of @disaggregate
*
* Data are from FRED. INDPRO is (monthly) industrial production, though
* we will use quarterly averages. GDPCA are annual GDP numbers (which
* start in 1929:1), GDPC1 are quarterly (starting in 1947:1). We'll use
* @DISAGGREGATE to create an estimate of quarterly GDP from 1929 on
* using industrial production as a related series.
*
open data demodisaggregate.rat
calendar(q) 1929:1
data(format=rats,compact=average) 1929:01 2012:04 indpro gdpc1 gdpca
*
* The model is log-linear using log IP as the explanatory variable, with
* an RWAR1 time series model, that is the assumed model at the quarterly
* level is
*
* log y(t) = beta x log ip(t) + z(t)
*
* where z(t) is an ARIMA(1,1,0) process
*
* with the constraint that the average of y across each year matches the
* observed value of GDPCA.
*
set logip = log(indpro)
@disaggregate(tsmodel=rwar1,model=loglin,factor=4,maintain=average,print) gdpca / gdpcq
# logip
*
* Over the full sample, the two lines run almost on top of each other,
* so this graphs the estimated quarterly value and the official
* quarterly value for a 10 year range.
*
graph(overlay=line,key=upleft,klabels=||"Official","Estimated","IP"||) 3
# gdpc1 2003:1 2012:4
# gdpcq 2003:1 2012:4
# indpro 2003:1 2012:4
Copyright © 2025 Thomas A. Doan