Command Reference : Working with Graphs : Creating a Graph
  
Creating a Graph
 
Displaying graphs using commands
Displaying graphs as object views
Creating graph objects from object views
Creating named graph objects
Specifying a graph by type
Merging graph objects
Creating unnamed graph objects
There are three types of graphs in EViews: graphs that are views of other objects, and named or unnamed graph objects. The commands provided for customizing the appearance of your graphs are available for use with named graph objects. You may use the dialogs interactively to modify the appearance of all types of graphs.
Displaying graphs using commands
The simplest way to display a graph view is to use one of the basic graph commands. (“Graph Creation Commands”)
Where possible EViews will simply open the object and display the appropriate graph view. For example, to display a line or bar graph of the series INCOME and CONS, you may simply issue the commands:
line income
bar cons
In other cases, EViews must first create an unnamed object and then will display the desired view of that object. For example:
scat x y z
first creates an unnamed group object containing the three series and then, using the scat view of a group, displays scatterplots of Y on X and Z on X in a single frame.
As with other EViews commands, graph creation commands allow you to specify a variety of options and arguments to modify the default graph settings. You may, for example, rotate the bar graph using the “rotate” option,
bar(rotate) cons
or you may display boxplots along the borders of your scatter plot using:
scat(ab=boxplot) x y z
Note that while using graph commands interactively may be quite convenient, these commands are not recommended for program use since you will not be able to use the resulting unnamed objects in your program.
The next section describes a more flexible approach to displaying graphs.
Displaying graphs as object views
You may display a graph of an existing object using a graph view command. For example, you may use the following two commands to display graph views of a series and a group:
ser2.area(n)
grp6.xypair
The first command plots the series SER2 as an area graph with normalized scaling. The second command provides an XY line graph view of the group GRP6, with the series plotted in pairs.
To display graphs for multiple series, we may first create a group containing the series and then display the appropriate view:
group g1 x y z
g1.scat
shows the scatterplot of the series in the newly created group G1.
There are a wide range of sophisticated graph views that you may display using commands. See “” for a detailed listing along with numerous examples.
Before proceeding, it is important to note that graph views of objects differ from graph objects in important ways:
First, graph views of objects may not be customized using commands after they are first created. The graph commands for customizing an existing graph are designed for use with graph objects.
Second, while you may use interactive dialogs to customize an existing object’s graph view, we caution you that there is no guarantee that the customization will be permanent. In many cases, the customized settings will not be saved with the object and will be discarded when the view changes or if the object is closed and then reopened.
In contrast, graph objects may be customized extensively after they are created. Any customization of a graph object is permanent, and will be saved with the object.
Since construction of a graph view is described in detail elsewhere (“”), we focus the remainder of our attention on the creation and customization of graph objects.
Creating graph objects from object views
If you wish to create a graph object from another object, you should combine the object view command with the freeze command. Simply follow the freeze keyword with an optional name for the graph object, and the object view to be frozen. For example,
freeze grp6.xypair(m)
creates and displays an unnamed graph object of the GRP6 view showing an XY line graph with the series plotted in pairs in multiple graph frames. Be sure to specify any desired graph options (e.g., “m”). Note that freezing an object view will not necessarily copy the existing custom appearance settings such as line color, axis assignment, etc. For this reason that we recommend that you create a graph object before performing extensive customization of a view.
You should avoid creating unnamed graphs when using commands in programs since you will be unable to refer to, or work with the resulting object in a program. Instead, you should tell EViews to create a named object, as in:
freeze(graph1) grp6.line
which creates a graph object GRAPH1 containing a line graph of the data in GRP6. By default, the frozen graph will have updating turned off, but in most cases you may use the Graph::setupdate graph proc to turn updating on.
Note that using the freeze command with a name for the graph will create the graph object and store it in the workfile without showing it. Furthermore, since we have frozen a graph type (line) that is different from our current XY line view, existing custom appearance settings will not be copied to the new graph.
Once you have created a named graph object, you may use the various graph object procs to further customize the appearance of your graph. See “Customizing a Graph”.
Creating named graph objects
There are three direct methods for creating a named graph object. First, you may use the freeze command as described above. Alternatively, you may declare a graph object using the graph command. The graph command may be used to create graph objects with a specific graph type or to merge existing graph objects.
Specifying a graph by type
To specify a graph by type you should use the graph keyword, followed by a name for the graph, the type of graph you wish to create, and a list of series (see “Graph Type Commands” for a list of types). If a type is not specified, a line graph will be created.
For example, both:
graph gr1 ser1 ser2
graph gr2.line ser1 ser2
create graph objects containing the line graph view of SER1 and SER2, respectively.
Similarly:
graph gr3.xyline group3
creates a graph object GR3 containing the XY line graph view of the series in GROUP3.
Each graph type provides additional options, which may be included when declaring the graph. Among the most important options are those for controlling scaling or graph type.
The scaling options include:
Automatic scaling (“a”), in which series are graphed using the default single scale. The default is left scale for most graphs, or left and bottom for XY graphs.
Dual scaling without crossing (“d”) scales the first series on the left and all other series on the right. The left and right scales will not overlap.
Dual scaling with possible crossing (“x”) is the same as the “d” option, but will allow the left and right scales to overlap.
Normalized scaling (“n”), scales using zero mean and unit standard deviation.
For example, the commands:
graph g1.xyline(d) unemp gdp inv
show g1
create and display an XY line graph of the specified series with dual scales and no crossing.
The graph type options include:
Mixed graph (“l”) creates a single graph in which the first series is the selected graph type (bar, area, or spike) and all remaining series are line graphs.
Multiple graph (“m”) plots each graph in a separate frame.
Stacked graph (“s”) plots the cumulative addition of the series, so the value of a series is represented as the difference between the lines, bars, or areas.
For example, the commands:
group grp1 sales1 sales2
graph grsales.bar(s) grp1
show grsales
create a group GRP1 containing the series SALES1 and SALES2, then create and display a stacked bar graph GRSALES of the series in the group.
You should consult the command reference entry for each graph type for additional information, including a list of the available options (i.e., see bar for complete details on bar graphs, and line for details on line graphs).
Merging graph objects
The graph command may also be used to merge existing named graph objects into a named multiple graph object. For example:
graph gr2.merge gr1 grsales
creates a multiple graph object GR2, combining two graph objects previously created.
Creating unnamed graph objects
There are two ways of creating an unnamed graph object. First, you may use the freeze command as described in “Creating graph objects from object views”.
As we have seen earlier you may also use any of the graph type keywords as a command (“Displaying graphs using commands”). Follow the keyword with any available options for that type, and a list of the objects to graph. EViews will create an unnamed graph of the specified type that is not stored in the workfile. For instance:
line(x) ser1 ser2 ser3
creates a line graph with series SER1 scaled on the left axis and series SER2 and SER3 scaled on the right axis.
If you later decide to name this graph, you may do so interactively by clicking on the Name button in the graph button bar. Alternatively, EViews will prompt you to name or delete any unnamed objects before closing the workfile.
Note that there is no way to name an unnamed graph object in a program. We recommend that you avoid creating unnamed graphs in programs since you will be unable to use the resulting object.